note 114065 modified in functions.arguments by sobak

From: Date: Fri, 29 Aug 2014 05:43:51 +0000
Subject: note 114065 modified in functions.arguments by sobak
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-200337@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. However, this feature is included as of PHP 5.6.0. See this page for more information: http://php.net/migration56.new-features#migration56.new-features.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-- 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; }). http://php.net/manual/en/functions.arguments.php

« previous php.notes (#200337) next »