Issue Bug Closed

#21857Type hints and optional parameters in substituteMarkerArrayCached

Michael Staatz 12/14/09, 16:00 updated 10/02/18, 12:24

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)

Reviews 0

No change resolves or names this issue in its commit message, and no comment links one.