This site has been archived. To learn more about our current products Ibexa Content, Ibexa Experience, Ibexa Commerce head over to the Ibexa Developer Portal

eZ Community » Forums » Feedback & ideas about the eZ... » ezpublish-legacy - Default...

ezpublish-legacy - Default parameters: null vs. false

ezpublish-legacy - Default parameters: null vs. false

Thursday 23 May 2013 9:22:34 pm - 1 reply

I have always wondered why, in the eZ Publish Legacy code, the default parameters for methods are often given as boolean, although (in my opinion) "null" would be more appropriate. 

As an example, please have a look at eZContentObjectTreeNode::fetch():

 static function fetch( $nodeID = false, $lang = false, $asObject = true, $conditions = false ) {}

$asObject should be a boolean, because we want to fetch the node either as an object (true) or as an array (false).

$nodeId and $lang should be null, to show that the variable has not been set

$conditions is a case not in the scope of my question, so I don't want to go too deep into that

So I think, the method definition should look like this:

 public static function fetch( $nodeID = null, $lang = null, $asObject = true, array $conditions = array()


What do you think?

- Jérôme 

Saturday 13 July 2013 4:46:00 pm

Hey Jérôme,

your questions seems very specific and in my opinion there is no huge difference from the original method to your proposed method. You just want to change datatypes of the parameters in cases of emptiness, right?

Using NULL as a value is never recommended. Because it is no value and could somehow somewhere drive you and your scripts into an asylum. Imagine something happens during runtime and some external ressource returns NULL.. ?

Maybe that helps you happy.gif Emoticon 

Cheers  Chris


You must be logged in to post messages in this topic!

36 542 Users on board!

Forums menu

Proudly Developed with from