Jump to content

Unusual Code - A PHP Shortcut?


iwato

Recommended Posts

<?=++$a?>
<?=++$b?>
<?=$private_id?>
<?=session_id()?> 

I found this on the internet amongst some other code, and it appears to work.  Unfortunately, I do not quite understand it.  Is <?= a shorthand for <?php echo ... ;

Link to comment
Share on other sites

Yes. <?= ?> is a shortcut for <?php echo ""; ?>

All of the above will translate as follows:

<?php echo ++$a; ?>
<?php echo ++$b; ?>
<?php echo $private_id; ?>
<?php echo session_id(); ?>

 

  • Like 1
Link to comment
Share on other sites

Just for reference, this technique is considered a bad practice because it's not portable. I would recommend against using it. It also has the issue that it's missing the "<?php" part of the processing instruction to let parsers know which type of system is meant to use the instruction.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...