Bug #21857
closedType hints and optional parameters in substituteMarkerArrayCached
0%
Description
Hi,
in my opinion it is not a good coding style to type hint a parameter as array and make it optional with a value = NULL.
public function substituteMarkerArrayCached($content, array $markContentArray = NULL, array $subpartContentArray = NULL, array $wrappedSubpartContentArray = NULL)
PHP can handle type hints with array since version 5.1! and the documentation says:
PHP 5 introduces Type Hinting. Functions are now able to force parameters to be objects (by specifying the name of the class in the function prototype) or arrays (since PHP 5.1). However, if NULL is used as the default parameter value, it will be allowed as an argument for any later call.
This means i can use an array OR NULL as parameter.
And in the method, at the first 5 Lines, there is a check if parameter is NULL and if so, it will be set to array:
if (is_null($markContentArray)) $markContentArray=array();
if (is_null($subpartContentArray)) $subpartContentArray=array();
if (is_null($wrappedSubpartContentArray)) $wrappedSubpartContentArray=array();
this is not necessary if the method will be defined properly, like
public function substituteMarkerArrayCached($content, array $markContentArray = array(), array $subpartContentArray = array(), array $wrappedSubpartContentArray = array()) {
i have a patch in the attachment.
Kind regards
Michael Staatz
(issue imported from #M13036)
Files
Updated by Jigal van Hemert almost 14 years ago
Support for NULL as parameter was done on purpose in issue #19446 to keep existing extensions working. Many extensions pass not-initialized variables to this function. Variables which are not initialized have the 'value' NULL in PHP, so the result was that many extensions produced fatal errors when type hinting was introduced.
Although the situation is not ideal, it was more important to not break many existing extensions.