note 79014 added to language.oop5.typehinting
| From: | jesdisciple at tgmail-dot-com | Date: | Wed, 07 Nov 2007 03:50:53 +0000 |
| Subject: | note 79014 added to language.oop5.typehinting | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-132064@lists.php.net to get a copy of this message | ||
The manual's sample code says:
<?php
//...
// Fatal Error: Argument 1 must not be null
$myclass->test(null);
//...
?>
And this is true, unless a default value of NULL is given; in fact, this is the only way to give a
default value for object arguments (as a default value must be a constant expression):
<?php
$mine = new MyClass();
$mine->test(NULL);
class MyClass{
public function __construct(OtherClass $arg = NULL){
if(is_null($arg)){
//Apply default value here.
}
}
public function test(array $arr = NULL){
print_r($arr);
}
}
class OtherClass{
}
?>
----
Server IP: 69.147.83.197
Probable Submitter: 72.251.10.188
----
Manual Page -- http://www.php.net/manual/en/language.oop5.typehinting.php
Edit -- https://master.php.net/note/edit/79014
Del: integrated -- https://master.php.net/note/delete/79014/integrated
Del: useless -- https://master.php.net/note/delete/79014/useless
Del: bad code -- https://master.php.net/note/delete/79014/bad+code
Del: spam -- https://master.php.net/note/delete/79014/spam
Del: non-english -- https://master.php.net/note/delete/79014/non-english
Del: in docs -- https://master.php.net/note/delete/79014/in+docs
Del: other reasons-- https://master.php.net/note/delete/79014
Reject -- https://master.php.net/note/reject/79014
Search -- https://master.php.net/manage/user-notes.php