Skip to main content
The 2024 Developer Survey results are live! See the results
added 419 characters in body
Source Link
hakre
  • 196k
  • 55
  • 444
  • 846

Unexpected '?'

If you are trying to use <?php within <?php this error will be given*.

$var = 'hello '<?php echo 'world'; ?>;

* For PHP versions 4.3.1, 4.3.5 - 4.3.11, 4.4.0 - 4.4.1, 5.0.0 - 5.0.5, 4.4.2 - 4.4.9, 5.1.0 - 5.1.6, 5.2.0 - 5.2.17, 5.3.0 - 5.3.29, 5.4.0 - 5.4.45, 5.5.0 - 5.5.38, 5.6.0 - 5.6.40, 7.0.0 - 7.0.33, 7.1.0 - 7.1.33, 7.2.0 - 7.2.34, 7.3.0 - 7.3.31, 7.4.0 - 7.4.24


If you are trying to use the null coalescing operator ?? in a version of PHP prior to PHP 7 you will get this error.

<?= $a ?? 2; // works in PHP 7+
<?= (!empty($a)) ? $a : 2; // All versions of PHP

Unexpected '?', expecting variable

A similar error can occur for nullable types, as in:

function add(?int $sum): ?int {

Which again indicates an outdated PHP version being used (either the CLI version php -v or the webserver bound one phpinfo();).

Unexpected '?'

If you are trying to use the null coalescing operator ?? in a version of PHP prior to PHP 7 you will get this error.

<?= $a ?? 2; // works in PHP 7+
<?= (!empty($a)) ? $a : 2; // All versions of PHP

Unexpected '?', expecting variable

A similar error can occur for nullable types, as in:

function add(?int $sum): ?int {

Which again indicates an outdated PHP version being used (either the CLI version php -v or the webserver bound one phpinfo();).

Unexpected '?'

If you are trying to use <?php within <?php this error will be given*.

$var = 'hello '<?php echo 'world'; ?>;

* For PHP versions 4.3.1, 4.3.5 - 4.3.11, 4.4.0 - 4.4.1, 5.0.0 - 5.0.5, 4.4.2 - 4.4.9, 5.1.0 - 5.1.6, 5.2.0 - 5.2.17, 5.3.0 - 5.3.29, 5.4.0 - 5.4.45, 5.5.0 - 5.5.38, 5.6.0 - 5.6.40, 7.0.0 - 7.0.33, 7.1.0 - 7.1.33, 7.2.0 - 7.2.34, 7.3.0 - 7.3.31, 7.4.0 - 7.4.24


If you are trying to use the null coalescing operator ?? in a version of PHP prior to PHP 7 you will get this error.

<?= $a ?? 2; // works in PHP 7+
<?= (!empty($a)) ? $a : 2; // All versions of PHP

Unexpected '?', expecting variable

A similar error can occur for nullable types, as in:

function add(?int $sum): ?int {

Which again indicates an outdated PHP version being used (either the CLI version php -v or the webserver bound one phpinfo();).

Commonmark migration
Source Link

##Unexpected '?'

Unexpected '?'

If you are trying to use the null coalescing operator ?? in a version of PHP prior to PHP 7 you will get this error.

<?= $a ?? 2; // works in PHP 7+
<?= (!empty($a)) ? $a : 2; // All versions of PHP

Unexpected '?', expecting variable

A similar error can occur for nullable types, as in:

function add(?int $sum): ?int {

Which again indicates an outdated PHP version being used (either the CLI version php -v or the webserver bound one phpinfo();).

##Unexpected '?'

If you are trying to use the null coalescing operator ?? in a version of PHP prior to PHP 7 you will get this error.

<?= $a ?? 2; // works in PHP 7+
<?= (!empty($a)) ? $a : 2; // All versions of PHP

Unexpected '?', expecting variable

A similar error can occur for nullable types, as in:

function add(?int $sum): ?int {

Which again indicates an outdated PHP version being used (either the CLI version php -v or the webserver bound one phpinfo();).

Unexpected '?'

If you are trying to use the null coalescing operator ?? in a version of PHP prior to PHP 7 you will get this error.

<?= $a ?? 2; // works in PHP 7+
<?= (!empty($a)) ? $a : 2; // All versions of PHP

Unexpected '?', expecting variable

A similar error can occur for nullable types, as in:

function add(?int $sum): ?int {

Which again indicates an outdated PHP version being used (either the CLI version php -v or the webserver bound one phpinfo();).

added 272 characters in body
Source Link
mario
  • 145.1k
  • 20
  • 240
  • 293

##Unexpected '?'

If you are trying to use the null coalescing operator ?? in a version of PHP prior to PHP 7 you will get this error.

<?= $a ?? 2; // works in PHP 7+
<?= (!empty($a)) ? $a : 2; // All versions of PHP

Unexpected '?', expecting variable

A similar error can occur for nullable types, as in:

function add(?int $sum): ?int {

Which again indicates an outdated PHP version being used (either the CLI version php -v or the webserver bound one phpinfo();).

##Unexpected '?'

If you are trying to use the null coalescing operator ?? in a version of PHP prior to PHP 7 you will get this error.

<?= $a ?? 2; // works in PHP 7+
<?= (!empty($a)) ? $a : 2; // All versions of PHP

##Unexpected '?'

If you are trying to use the null coalescing operator ?? in a version of PHP prior to PHP 7 you will get this error.

<?= $a ?? 2; // works in PHP 7+
<?= (!empty($a)) ? $a : 2; // All versions of PHP

Unexpected '?', expecting variable

A similar error can occur for nullable types, as in:

function add(?int $sum): ?int {

Which again indicates an outdated PHP version being used (either the CLI version php -v or the webserver bound one phpinfo();).

Source Link
John Conde
  • 218.9k
  • 99
  • 461
  • 501
Loading
Post Made Community Wiki by John Conde