note 114065 modified in functions.arguments by tularis

From: Date: Wed, 08 Jan 2014 12:56:28 +0000
Subject: note 114065 modified in functions.arguments by tularis
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-198153@lists.php.net to get a copy of this message
Editor's note: what is expected here by the parser is a non-evaluated expression. An operand and two constants requires evaluation, which is not done by the parser. This feature however will be included as of PHP 5.6.0 (not yet released at the time of writing). See this RFC for more information: https://wiki.php.net/rfc/const_scalar_exprs -------- "The default value must be a constant expression" is misleading (or even wrong). PHP 5.4.4 fails to parse this function definition: function htmlspecialchars_latin1($s, $flags = ENT_COMPAT | ENT_HTML401) {} This yields a " PHP Parse error: syntax error, unexpected '|', expecting ')' " although ENT_COMPAT|ENT_HTML401 is certainly what a compiler-affine person would call a "constant expression". The obvious workaround is to use a single special value ($flags = NULL) as the default, and to set it to the desired value in the function's body (if ($flags === NULL) { $flags = ENT_COMPAT | ENT_HTML401; }). --was-- "The default value must be a constant expression" is misleading (or even wrong). PHP 5.4.4 fails to parse this function definition: function htmlspecialchars_latin1($s, $flags = ENT_COMPAT | ENT_HTML401) {} This yields a " PHP Parse error: syntax error, unexpected '|', expecting ')' " although ENT_COMPAT|ENT_HTML401 is certainly what a compiler-affine person would call a "constant expression". The obvious workaround is to use a single special value ($flags = NULL) as the default, and to set it to the desired value in the function's body (if ($flags === NULL) { $flags = ENT_COMPAT | ENT_HTML401; }). http://php.net/manual/en/functions.arguments.php

« previous php.notes (#198153) next »