Public Member Functions | |
Code ($code=false) | |
__construct ($code=false) | |
& | execute () |
compile () | |
setCode ($str) | |
getCode () | |
__sleep () | |
toString () | |
Public Attributes | |
$_code | |
$_function | |
$_compiled = false |
The aim of this class is to dynamically generate executable php code from php string.
This kind of object can be safely serialized as the code it represents is stored in the _code member variable.
When setting code to this object, a new anonymous function is created waiting to be invoqued using the execute() method.
As we can't know how many parameters this function should take, a 'context' hashtable is used as only parameter. This hash may contains any number of arguments with var name compliant keys.
Code object automatically append 'extract' code string to produced code.
It's up to the code to assert parameters using 'isset()' php function.
<?php require_once PT_IP . "/Types/Code.php";
$o_code = Code() $o_code->setCode('return $foo . $bar . $baz;'); $res = $o_code->execute( 'foo', 'foo value ', 'baz', 'bar value ', 'baz', 'baz value' );
// will print 'foo value bar value baz value' echo $res, end; ?>
Definition at line 78 of file Code.php.
|
Construct a new code object.
|
|
Definition at line 95 of file Code.php. References __construct(), and setCode(). Referenced by __construct(). |
|
On serialization, we store only code, not additional variables. private |
|
Compile php code. This function may produce parse errors.
|
|
Execute code with specific context.
|
|
Retrieve code.
|
|
Set function code.
Definition at line 166 of file Code.php. Referenced by __construct(). |
|
Make a string representation of this object.
|
|
|
|
|
|
|