Bug #23893
closed
Add type hints for function parameters in tslib_content
Added by Jigal van Hemert about 14 years ago.
Updated over 9 years ago.
Description
Functions in tslib_content do not have type hints for array or object parameters.
Problem: if you pass a string instead of an array PHP will try to index this string instead of using parts of the array. This will lead to errors about trying to use a string offset.
If a type hint is used there will be a clear error that the wrong type was used.
This was discussed with Joey Hasenau who has taken care of the restructuring of the stdWrap functions in tslib_content.
(issue imported from #M16194)
Has been discussed for some other methods already in the core list, and adding type hinting is nice but breaks compatibility, because this is the API we used to have. Most common problem is:
$conf meant to be an array()
But extensions passing "NULL" to it. This is not compatible with type hinting "array" and will generate a fatal error.
So that cleanup can only be done by deprecating all methods and introducing new ones, or simply ignoring this backwards compatibility problem, which I would like to postpone to 4.6. :)
function test (array $arg = NULL) {
allows NULL, unset variables and array to be passed as argument. Other types trigger an exception.
You need to test for NULL and set $arg to an empty array and you're backwards compatible with NULL values.
At least passing a string will not cause erratic behaviour because PHP will otherwise trying to index strings.
Seems to be the same problem as #24462
- Target version changed from 4.6.0 to 4.6.1
- Target version changed from 4.6.1 to 4.6.2
- Target version deleted (
4.6.2)
- Status changed from New to Needs Feedback
- Is Regression set to No
- Status changed from Needs Feedback to Closed
No feedback within the last 90 days => closing this issue.
If you think that this is the wrong decision or experience this issue again, then please write to the mailing list typo3.teams.bugs with issue number and an explanation or open a new ticket and add a relation to this ticket number.
Also available in: Atom
PDF