note 63236 modified in function.func-num-args by danbrown
| From: | danbrown@php.net | Date: | Sat, 19 Jul 2008 21:52:20 +0000 |
| Subject: | note 63236 modified in function.func-num-args by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-141769@lists.php.net to get a copy of this message | ||
This function comes in extremely handy in OO Classes. My focus is currently PHP 4, but this
technique probably works just as well in PHP 5.
<?php
Class foo {
// constructor, other methods, etc
function somedata($somedata = '') {
if (func_num_args() > 0) {
$this->somedata = $somedata;
}
return $this->somedata;
}
}
?>
This allows for a default value to be set, while not requiring the parameter. (Yes, I'm aware
that it only warns when you do, but I think this is a little cleaner)
--was--
This function comes in extremely handy in OO Classes. My focus is currently PHP 4, but this
technique probably works just as well in PHP 5.
Class foo {
// constructor, other methods, etc
function somedata($somedata = '') {
if (func_num_args() > 0) {
$this->somedata = $somedata;
}
return $this->somedata;
}
}
This allows for a default value to be set, while not requiring the parameter. (Yes, I'm aware
that it only warns when you do, but I think this is a little cleaner)
http://php.net/manual/en/function.func-num-args.php