egingell at sisna dot com -
Use of __call makes "overloading" possible also,
although somewhat clunky... i.e.
<?php
class overloadExample
{
function __call($fName, $fArgs)
{
if ($fName == 'sum')
{
if (count ($fArgs) === 1)
{
return $fArgs[0];
}
else
{
$retVal = 0;
foreach( $fArgs as $arg )
{
$retVal += $arg;
}
return $retVal;
}
}
}
}
/*
Simple and trivial I realize, but the point is made. Now an
object of class overloadExample can take
*/
echo $obj->sum(4); // returns 4
echo $obj->sum(4, 5); // returns 9
?>
----
Server IP: 208.69.120.35
Probable Submitter: 72.145.80.162
----
Manual Page -- http://www.php.net/manual/en/language.oop5.overloading
.php
Edit -- https://master
.php.net/note/edit/78373
Del: integrated -- h
ttps://master.php.net/note/delete/78373/integrated
Del: useless -- http
s://master.php.net/note/delete/78373/useless
Del: bad code -- htt
ps://master.php.net/note/delete/78373/bad+code
Del: spam -- https:/
/master.php.net/note/delete/78373/spam
Del: non-english --
https://master.php.net/note/delete/78373/non-english
Del: in docs -- http
s://master.php.net/note/delete/78373/in+docs
Del: other reasons-- https://mast
er.php.net/note/delete/78373
Reject -- https://mast
er.php.net/note/reject/78373
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
|