#46899 [NEW]: Typed function arguments should allow nulls

From: Date: Thu, 18 Dec 2008 13:33:56 +0000
Subject: #46899 [NEW]: Typed function arguments should allow nulls
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-132137@lists.php.net to get a copy of this message
From: zyss at mail dot zp dot ua Operating system: Irrelevant PHP version: 5.2.8 PHP Bug Type: Feature/Change Request Bug description: Typed function arguments should allow nulls 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 bug report at http://bugs.php.net/?id=46899&edit=1 -- Try a CVS snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=46899&r=trysnapshot52 Try a CVS snapshot (PHP 5.3): http://bugs.php.net/fix.php?id=46899&r=trysnapshot53 Try a CVS snapshot (PHP 6.0): http://bugs.php.net/fix.php?id=46899&r=trysnapshot60 Fixed in CVS: http://bugs.php.net/fix.php?id=46899&r=fixedcvs Fixed in CVS and need be documented: http://bugs.php.net/fix.php?id=46899&r=needdocs Fixed in release: http://bugs.php.net/fix.php?id=46899&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=46899&r=needtrace Need Reproduce Script: http://bugs.php.net/fix.php?id=46899&r=needscript Try newer version: http://bugs.php.net/fix.php?id=46899&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=46899&r=support Expected behavior: http://bugs.php.net/fix.php?id=46899&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=46899&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=46899&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=46899&r=globals PHP 4 support discontinued: http://bugs.php.net/fix.php?id=46899&r=php4 Daylight Savings: http://bugs.php.net/fix.php?id=46899&r=dst IIS Stability: http://bugs.php.net/fix.php?id=46899&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=46899&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=46899&r=float No Zend Extensions: http://bugs.php.net/fix.php?id=46899&r=nozend MySQL Configuration Error: http://bugs.php.net/fix.php?id=46899&r=mysqlcfg

« previous php.bugs (#132137) next »