Main Page | Namespace List | Class Hierarchy | Class List | File List | Class Members | File Members | Related Pages

Code Class Reference

List of all members.

Public Member Functions

 Code ($code=false)
 __construct ($code=false)
execute ()
 compile ()
 setCode ($str)
 getCode ()
 __sleep ()
 toString ()

Public Attributes

 $_code
 $_function
 $_compiled = false

Detailed Description

Code class handle and evaluate php code.

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; ?>

Author:
Laurent Bedubourg <laurent.bedubourg@free.fr>

Definition at line 78 of file Code.php.


Constructor & Destructor Documentation

Code::Code code = false  ) 
 

Construct a new code object.

Parameters:
mixed $code (optional) php code string or object implementing toString method.

Definition at line 90 of file Code.php.


Member Function Documentation

Code::__construct code = false  ) 
 

Definition at line 95 of file Code.php.

References __construct(), and setCode().

Referenced by __construct().

Code::__sleep  ) 
 

On serialization, we store only code, not additional variables.

private

Definition at line 188 of file Code.php.

Code::compile  ) 
 

Compile php code.

This function may produce parse errors.

Exceptions:
CodeError 

Definition at line 146 of file Code.php.

& Code::execute  ) 
 

Execute code with specific context.

Parameters:
mixed ... The function execution context. This may be an associative array, an OHash object, a list of key/value pairs that will be transformed into an associative array
Returns:
mixed The execution result.

Definition at line 117 of file Code.php.

Code::getCode  ) 
 

Retrieve code.

Returns:
string

Definition at line 178 of file Code.php.

Code::setCode str  ) 
 

Set function code.

Parameters:
string $str The php code string

Definition at line 166 of file Code.php.

Referenced by __construct().

Code::toString  ) 
 

Make a string representation of this object.

Returns:
string

Definition at line 198 of file Code.php.


Member Data Documentation

Code::$_code
 

Definition at line 80 of file Code.php.

Code::$_compiled = false
 

Definition at line 82 of file Code.php.

Code::$_function
 

Definition at line 81 of file Code.php.


The documentation for this class was generated from the following file:
Generated on Tue Jun 29 23:40:21 2004 for Mediawiki by doxygen 1.3.7