ID: 46899 Comment by: zyss at mail dot zp dot ua Reported By: zyss at mail dot zp dot ua Status: Open Bug Type: Feature/Change Request Operating System: Irrelevant PHP Version: 5.2.8 New Comment:
Example in more readable form: class ExElement extends Exception { }; class Element { // each element references document for fast access protected /* Document */ $document; protected /* Element */ $parent; function __construct( Document $document, Element $parent = null) /* throws ExElement */ { // is still checked to be valid Document object reference $this->document = $document; if ($parent && ($parent->getDocument() != $document)) throw new ExElement("Parent's document doesn't match " . "Element constructor's argument", 1); $this->parent = $parent; } function getDocument() { return $this->document; } } Previous Comments: ------------------------------------------------------------------------ [2008-12-18 13:33:55] zyss at mail dot zp dot ua Description: ------------ Currently class type can be specified as function argument type, but it is frequently required to pass null instead of object reference when there is a default argument value set and it is null. In the following example constructor's $parent argument can be null for the top-level objects, but current PHP version doesn't allow it to be null forcing to remove type declaration that is very undesirable: class ExElement extends Exception { }; class Element { protected /* Document */ $document; // each element references document for fast access protected /* Element */ $parent; function __construct(Document $document, Element $parent = null) /* throws ExElement */ { $this->document = $document; // is still checked by PHP to be valid Document object reference if ($parent && ($parent->getDocument() != $document)) throw new ExElement("Parent's document doesn't match Element constructor's argument", 1); $this->parent = $parent; } function getDocument() { return $this->document; } } ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=46899&edit=1