note 93072 deleted from language.oop5.overloading by peehaa
| From: | peehaa@php.net | Date: | Mon, 08 Jul 2013 20:20:12 +0000 |
| Subject: | note 93072 deleted from language.oop5.overloading by peehaa | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-195518@lists.php.net to get a copy of this message | ||
Note Submitter: kexianbin at diyism dot com
----
By using __call, we can use php as using jQuery:
<?php
//SoWork PHP Framework
define('this', mt_rand());
$o='so_work';
class cls_so_work
{function __call($fun, $pars)
{foreach ($pars as &$v)
{if ($v===this)
{$v=$this->val;
break;
}
}
$tmp=eval('return
defined("'.$fun.'")?constant("'.$fun.'"):"'.$fun.'";');
$this->val=call_user_func_array($tmp, $pars);
return $this;
}
function cls_so_work($obj)
{$this->val=isset($obj)?$obj:null;
}
}
function so_work($obj)
{if (isset($obj))
{return new cls_so_work($obj);
}
else
{if (!isset($GLOABALS['so_work']))
{$GLOABALS['so_work']=new cls_so_work();
}
else
{$GLOABALS['so_work']->val=null;
}
return $GLOABALS['so_work'];
}
}
define('echo', 'my_echo');
function my_echo($obj)
{echo $obj;
return $obj;
}
$o('abcd')->substr(this, 2, 2)->strlen(this)->echo(this);
$o()->substr('abcd', 1, 3)->strlen(this)->echo(this);
?>