note 42582 added to ref.overload
| From: | almethot at yahoo dot com | Date: | Sat, 22 May 2004 04:33:40 +0000 |
| Subject: | note 42582 added to ref.overload | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-69932@lists.php.net to get a copy of this message | ||
Here is a cleaner way to fake overloading which is a modification on
fabiostt[X_AT_X]libero[X_DOT_X]it
12-Aug-2003 01:56 posting. This example allows you to reuse the object and not have to re-create the
object everytime the variables need to change.
Hope this helps,
<?
Class NCSession
{
//Class Variables
Var $sessionResult = null;
// Sims Overloading in PHP - Yes it is crap but it works until you move to PHP 5.
function ncStartSession()
{
$numArgs = func_num_args() ; //number of args
$args = func_get_args() ; //array containing args
$x = call_user_func_array( array( &$this, 'ncStartSession'.$numArgs), $args) ;
$sessionResult = $x;
return $sessionResult;
}
function ncStartSession0()
{
session_start();
$sessionResult = "SUCCESS|YES|SESSIONID|" . session_id();
session_destroy();
return $sessionResult;
}
function ncStartSession1($arg)
{
session_start($arg);
$sessionResult = "SUCCESS|YES|SESSIONID|" . session_id();
session_destroy();
return $sessionResult;
}
}
//End of Class
$myTestSession = NEW NCSession();
$myResult = $myTestSession->ncStartSession();
echo "\n\$myResult = $myResult\n";
?>
----
Manual Page -- http://www.php.net/manual/en/ref.overload.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+42582
Delete -- http://master.php.net/manage/user-notes.php?action=delete+42582&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+42582&report=yes
Search -- http://master.php.net/manage/user-notes.php