note 42582 deleted from ref.overload by sobak
| From: | sobak@php.net | Date: | Tue, 22 Nov 2016 03:49:26 +0000 |
| Subject: | note 42582 deleted from ref.overload by sobak | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-207450@lists.php.net to get a copy of this message | ||
Note Submitter: almethot at yahoo dot com
----
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";
?>