[TYPO3-core] RFC: #7350:PHP5ize class.t3lib_div.php

Martin Kutschker martin.kutschker-n0spam at no5pam-blackbox.net
Sat Feb 2 13:06:25 CET 2008


Martin Kutschker schrieb:
> Michael Stucki schrieb:
>> Hi Dmitry,
>>
>>> Stanislas Rolland wrote:
>>>> tslib_content fails:
>>>>
>>>> Catchable fatal error: Argument 1 passed to
>>>> t3lib_div::implodeAttributes() must be an array, null given, called in
>>>> /typo3/sysext/cms/tslib/class.tslib_content.php on line 4471
>>> t3lib_div::get_tag_attributes did not work according to 
>>> documentation. Fix
>>> is attached. It may be sensitive, so I post here instead of
>>> autocommitting.
>>>
>>> Anyway, I feel bad about mixng return value and no return value 
>>> inside one
>>> function, which is declared as always returning value.
>>
>> How about returning false instead of an empty array?
> 
> But no attributes at all are no failure. An empty array is exactly what 
> the function should return.
> 
>> Someone who is using it
>> now could have checked the output using is_array(), which would match 
>> now.
> 
> Well, in tslib_context it's like this;
> 
> if (!is_array($returnedAttributes)) {
>   $returnedAttributes = array();
> }
> 
> I guess other could would work similar.
> 
>> Additional comments.
>>
>> Have a look at t3lib_div::xmlGetHeaderAttribs() - it says that it returns
>> string values, but the output is coming directly from 
>> get_tag_attributes().
>> Don't know if the phpdoc comment is wrong, at least I don't see how
>> get_tag_attributes() could ever return a string output. But we need to
>> check it thoroughly.
> 
> Ouch, the function has issues (ie it cannot work at all). It simply 
> looks for the XML prologue and feeds it into get_tag_attributes. may the 
> code that was initially written deals with the real return value.
> 
> But as it is, it's broken completely. Mybe we can check, when it went 
> into the Core and who is actually using it.

Ok, there are two uses in the Core. Both uses expect an array. They use 
later on a $attrArr['encoding']. Interestingly both occurences do 
lowercase the encoding themselves, so the lowercasing, which is IMHO 
wrongly used here (it will destroy possibly required cases), can be removed.

My conclusion: Dmitry's fix is correct. Folks expect 
get_tag_attributes() to return an array, so let's do it. The docs for 
xmlGetHeaderAttribs() are wrong. I suggest to change it, and also to 
remove lower casing of the xml prologue.

Masi


More information about the TYPO3-team-core mailing list