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 -- h
ttps://master.php.net/note/delete/79014/integrated
Del: useless -- http
s://master.php.net/note/delete/79014/useless
Del: bad code -- htt
ps://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 -- http
s://master.php.net/note/delete/79014/in+docs
Del: other reasons-- https://mast
er.php.net/note/delete/79014
Reject -- https://mast
er.php.net/note/reject/79014
Search -- https://
master.php.net/manage/user-notes.php
--
PHP Notes Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub
.php
|