Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed #18592: php warning on array_merge when 2nd arg is not an array #139

Merged
merged 2 commits into from
Oct 25, 2011

Conversation

jdespatis
Copy link
Contributor

Fixed #18592: php warning on array_merge when 2nd arg is not an array, when a datatype template contains no \n

@@ -1757,7 +1757,7 @@ class eZTemplate
if ( eZTemplate::isXHTMLCodeIncluded() )
$preText .= "<p class=\"small\">$path</p><br/>\n";
$postText = "\n<!-- STOP: including template: $path ($uri) -->\n";
$root[1] = array_merge( array( eZTemplateNodeTool::createTextNode( $preText ) ), $root[1] );
$root[1] = array_merge( array( eZTemplateNodeTool::createTextNode( $preText ) ), is_array( $root[1] ) ? $root[1] : array() );
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You don't have to do a merge at all if it is not an array.

@andrerom
Copy link
Contributor

Also note that our coding standards mentions having newlines at the end of the file (except in ezxmltext templates), that would avoid this issue wouldn't it?

@jdespatis
Copy link
Contributor Author

Yes it would!
Where can I read those coding standards?

=> So I can close this pull request?

@andrerom
Copy link
Contributor

http://share.ez.no/blogs/bertrand-dunogier/the-ez-coding-standards-need-you

As for closing or not, what do you/others think?
Could be the CS doc is not clear enough on this though, so might still be worth pulling in for convenience.

@jdespatis
Copy link
Contributor Author

New commit André from your remark.

Concerning the standards, some remarks:
1/ yes, if following the ez coding standards, this php warning would never occur
2/ there're already several php coding standards, some persons prefer to avoid \n at end of line, other prefer to add a beginning , that way the php file can end with several \n, but no \n will be used in the ending html pushed to client. As a result, not so sure all developers (already accustomed to a specific coding standard) would follow the ez standard for this ending \n
3/ in a world of productivity, not so sure ez coding standard would be strictly followed all the time (if no automatic checker can be launched to analyse quality of code and those standards), quite easy to forget a \n at end of line if the editor has not an option to add it automatically
4/ we cannot say strictly that adding a \n at end of file is an unilateral rule, as ezxmltext template should not end with a \n (maybe in the future, it'll be forbidden to add some \n to other templates)
5/ this patch adds an extra test is_array() (that would avoid an unecessary array_merge on some cases), so it's not time consuming. Further more I think this extra test is launched only one time as templates are cached
6/ eZ yells if a template doesn't exist for a datatype, so adding an empty .tpl is a common task for a lot of developers already

So for all those reasons (specially 4/ that says \n should be added to all files, except some... (and maybe others in the future)), I would say it would be nice to add an extra check to avoid this warning that may occur quite often (6/)

just my 2 cents :)

andrerom added a commit that referenced this pull request Oct 25, 2011
Fixed #18592: php warning on array_merge when 2nd arg is not an array
@andrerom andrerom merged commit cce66cb into ezsystems:master Oct 25, 2011
@andrerom
Copy link
Contributor

Agreed, merged, closed, thanks :)

peterkeung pushed a commit to peterkeung/ezpublish that referenced this pull request Jul 10, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants