note 98425 added to functions.arguments

From: Date: Tue, 15 Jun 2010 11:48:44 +0000
Subject: note 98425 added to functions.arguments
Groups: php.notes 
Request: Send a blank email to php-notes+get-170133@lists.php.net to get a copy of this message
You can use (very) limited signatures for your functions, specifing type of arguments allowed. For example: public function Right( My_Class $a, array $b ) tells first argument have to by object of My_Class, second an array. My_Class means that you can pass also object of class that either extends My_Class or implements (if My_Class is abstract class) My_Class. If you need exactly My_Class you need to either make it final, or add some code to check what $a really. Also note, that (unfortunately) "array" is the only built-in type you can use in signature. Any other types i.e.: public function Wrong( string $a, boolean $b ) will cause an error, because PHP will complain that $a is not an *object* of class string (and $b is not an object of class boolean). So if you need to know if $a is a string or $b bool, you need to write some code in your function body and i.e. throw exception if you detect type mismatch (or you can try to cast if it's doable). ---- Server IP: 194.24.174.37 Probable Submitter: 89.78.130.5 ---- Manual Page -- http://www.php.net/manual/en/functions.arguments.php Edit -- https://master.php.net/note/edit/98425 Del: integrated -- https://master.php.net/note/delete/98425/integrated Del: useless -- https://master.php.net/note/delete/98425/useless Del: bad code -- https://master.php.net/note/delete/98425/bad+code Del: spam -- https://master.php.net/note/delete/98425/spam Del: non-english -- https://master.php.net/note/delete/98425/non-english Del: in docs -- https://master.php.net/note/delete/98425/in+docs Del: other reasons-- https://master.php.net/note/delete/98425 Reject -- https://master.php.net/note/reject/98425 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#170133) next »