Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does '<?=' mean in PHP?

Tags:

syntax

php

People also ask

What does mean :: in PHP?

In PHP, the double colon :: is defined as Scope Resolution Operator. It used when when we want to access constants, properties and methods defined at class level. When referring to these items outside class definition, name of class is used along with scope resolution operator.

What does a $$$ mean in PHP?

The $x (single dollar) is the normal variable with the name x that stores any value like string, integer, float, etc. The $$x (double dollar) is a reference variable that stores the value which can be accessed by using the $ symbol before the $x value. These are called variable variables in PHP.

What does += mean in PHP?

The . operator is the string concatenation operator. . = will concatenate strings. The + operator is the addition operator. += will add numeric values.

What is %s and %D in PHP?

Those are placeholders for the variables that follow. %d means treat it as a number. %s means treat it as a string. The list of variables that follow in the function call are used in the order they show up in the preceding string.


It's a shorthand for <?php echo $a; ?>.

It's enabled by default since 5.4.0 regardless of php.ini settings.


It's a shorthand for this:

<?php echo $a; ?>

They're called short tags; see example #1 in the documentation.


Since it wouldn't add any value to repeat that it means echo, I thought you'd like to see what means in PHP exactly:

Array
(
    [0] => Array
        (
            [0] => 368 // T_OPEN_TAG_WITH_ECHO
            [1] => <?=
            [2] => 1
        )
    [1] => Array
        (
            [0] => 309 // T_VARIABLE
            [1] => $a
            [2] => 1
        )
    [2] => ; // UNKNOWN (because it is optional (ignored))
    [3] => Array
        (
            [0] => 369 // T_CLOSE_TAG
            [1] => ?>
            [2] => 1
        )
)

You can use this code to test it yourself:

$tokens = token_get_all('<?=$a;?>');
print_r($tokens);
foreach($tokens as $token){
    echo token_name((int) $token[0]), PHP_EOL;
}

From the List of Parser Tokens, here is what T_OPEN_TAG_WITH_ECHO links to.


<?= $a ?> is the same as <? echo $a; ?>, just shorthand for convenience.


<?=$a; ?>

is a shortcut for:

<?php echo $a; ?>

As of PHP 5.4.0, <?= ?> are always available even without the short_open_tag set in php.ini.

Furthermore, as of PHP 7.0, The ASP tags: <%, %> and the script tag <script language="php"> are removed from PHP.


It's a shortcut for <?php echo $a; ?> if short_open_tags are enabled. Ref: http://php.net/manual/en/ini.core.php