note 105235 added to language.oop5.decon
| From: | Anonymous at osu1 dot php dot net | Date: | Thu, 04 Aug 2011 08:49:02 +0000 |
| Subject: | note 105235 added to language.oop5.decon | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-182210@lists.php.net to get a copy of this message | ||
@misha at gmail dot com
You can always add more parameters to function/method calls than the function/method expects. Use
func_get_args() in your function/method to get all arguments. This allows you to create
functions/methods with variable number of arguments. Example:
<?php
class Add {
private $sum = 0;
public function __construct() {
$args = func_get_args();
foreach ($args as $arg) {
$sum += $arg;
}
}
public function result() {
return $this->sum;
}
}
$add = new Add(3, 5, 10);
echo $add->result();
----
Server IP: 69.147.83.197
Probable Submitter: 81.196.180.29
----
Manual Page -- http://www.php.net/manual/en/language.oop5.decon.php
Edit -- https://master.php.net/note/edit/105235
Del: integrated -- https://master.php.net/note/delete/105235/integrated
Del: useless -- https://master.php.net/note/delete/105235/useless
Del: bad code -- https://master.php.net/note/delete/105235/bad+code
Del: spam -- https://master.php.net/note/delete/105235/spam
Del: non-english -- https://master.php.net/note/delete/105235/non-english
Del: in docs -- https://master.php.net/note/delete/105235/in+docs
Del: other reasons-- https://master.php.net/note/delete/105235
Reject -- https://master.php.net/note/reject/105235
Search -- https://master.php.net/manage/user-notes.php