Project

General

Profile

Actions

Bug #21857

closed

Type hints and optional parameters in substituteMarkerArrayCached

Added by Michael Staatz almost 15 years ago. Updated about 6 years ago.

Status:
Closed
Priority:
Should have
Category:
Communication
Target version:
-
Start date:
2009-12-14
Due date:
% Done:

0%

Estimated time:
TYPO3 Version:
4.3
PHP Version:
5.3
Tags:
Complexity:
Is Regression:
Sprint Focus:

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

substituteMarkerArrayCached.diff (1.24 KB) substituteMarkerArrayCached.diff Administrator Admin, 2009-12-14 16:00

Related issues 1 (0 open1 closed)

Related to TYPO3 Core - Feature #19446: substituteMarkerArrayCached is too strict for older extensionsClosedErnesto Baschny2008-10-10

Actions
Actions #1

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.

Actions #2

Updated by Benni Mack about 6 years ago

  • Status changed from Resolved to Closed
Actions

Also available in: Atom PDF