note 100329 deleted from language.oop5 by danbrown

From: Date: Fri, 08 Oct 2010 12:27:25 +0000
Subject: note 100329 deleted from language.oop5 by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-173079@lists.php.net to get a copy of this message
Note Submitter: Daniel Alvarez Arribas ---- <quote>"[...]1) You cannot type hint string or int/integer in a method signature. This is incredibly annoying that the Zend II engine doesn't support it, but there are workarounds. 2) Supplying null in a method signature for a default value means that you will not accept any null value for that parameter. (therefore the method doesn't need to check if the parameters are null anyway). 3) Sadly, overriding methods is only possible with the Zend II engine via Inheritance or Polymorphism, ( and __construct() can only be defined within a class). If you want to override a method in the same class, my suggestion is to provide the method signature with a $flag = null variable, which you call a SWITCH on to pick what the data should do.[...]"</quote> Point 2 is simply wrong information. The contrary is the case: If and only if a default value of null is defined for an object-type formal method parameter, arguments passed may be null. Providing a null-valued argument for any formal object-type method parameter that does not have a default value of null, will raise a fatal error. See the PHP manual section on type hinting: "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." Point 3 is nonsense too. 1) In object-oriented programming inheritance is always a requirement for overriding a method - unless you replace it reflectively, thus breaking the OOP-behaviour - and 2) Where else would you want to define a __construct() method - if not in a class? I think the author is referring specifically to the feature of being able to define various methods with the same name (but different method signatures) in the same class, which PHP, as for now, does not support (by design). I request that the post quoted be deleted, because it provides wrong information and confuses users. It just steals everyones time.

« previous php.notes (#173079) next »