Implicit Evaluation with PHP Archives: Implicit Evaluation
·
30 January 2007
PHP as a Lambda Language
PHP is an imperative language which supports object-oriented programming. However, it supports a number of paradigms closer to what you would expect Lisp or Scheme to allow. I’ve discussed parts of this before, but its time to put together a definitive primer. You’ll learn ways to create entire functions at run time, as well as applying them to entire arrays in a single pass. PHP will seem more LISP-like than it ever has before.
continue reading... » 7 Comments
27 September 2006
Tail Recursion in PHP
There are two types of recursion in the world: tail recursive and non-tail recursive. Non-tail recursive is the more obvious of the two and is used frequently. For instance, when dealing with any kind of hierarchical data (that which is expressed in a tree data structure) a recursive call is likely used to construct the […]
continue reading... » One Comment
23 August 2006
Official Introspection, Reflect and Implicit Evaluation PHP.net resources
PHP.net actually provides documentation for each of these topics, but finding it can prove difficult. The following is a collection of the links I’ve discovered.
PHP5 Reflection Classes: These are explicit reflection methods specific to PHP5. I’ve never used them.
Object introspection functions: Introspection functions. There are slight differences in some between PHP4 and PHP5.
Zend Debugger Extensions: […]
continue reading... » 0 Comments
21 August 2006
Variable representation in PHP
In PHP, I like to think each function has its own Dictionary/Hash to manage its scope and that code outside of functions is actually part of a “Main” function. I think of it as a dictionary because through implicit evaluation, you can create variables with spaces and other reasons you’ll see at the conclusion of […]
continue reading... » 0 Comments
1 August 2006
Eval Preformance
I’ve always assumed implicit evaluation was faster than eval, but today, I finally tested that. Eval is four times slower than implicit evaluation.
// Eval Sample
$var = 1;
for ($x = 0; $x < 100000; $x++) {
eval (”$w$var=$var++;”);
}
// Implicit Sample
$var = 1;
for ($x = 0; $x < 100000; $x++) {
$strVar = ‘w’ . $var;
$$strVar = $var++;
}
Each sample […]
continue reading... » 0 Comments
6 January 2006
I used eval() today
Just as self-diagnosis is frowned upon in the medical world, I hesitate to say that my use of eval() was approriate. I’ve been working on a library to transcode HTML into another format, and it became neccessary to support PHP in addition to static HTML. I couldn’t dump to the shell and execute the file […]
continue reading... » 0 Comments
2 January 2006
Evaluating Variables in PHP
This article covers traditional PHP evaluation. There is also an article on implicit PHP evaluation (dynamic evaluation without using eval) if you’d prefer.
I normally discuss the more advanced side of evaluation in this column, but while checking the referral logs today, I found a fair number of visitors coming from Google with searchs like “evaluating […]
continue reading... » 0 Comments
2 January 2006
Limitations of Implicit Evaluation
Implicit evaluation is a very useful thing. For the sake of anyone new to it, implicit evaluation basically lets us treat a variable’s value as an identifier.
$fn = “print”;
$fn (”hello, world!”);
$color = “red”;
$$color = “#ff0000″;
echo $red;
In many ways, it is equivelent to having C/C++’s DEFINE directive as a part of the interpretter rather than pre-processor. […]
continue reading... » 0 Comments
6 December 2005
What is Implicit Evaluation
This article covers implicit PHP evaluation. There is also an article on traditional PHP evaluation (dynamic evaluation using eval) if you’d prefer.
Evaluation is a technique, which, simply refers to evaluating code at runtime. Microsoft Excel does this when a formula is entered in a cell. Many programming languages offer this functionality through various avenues: Mozilla-based […]
continue reading... » 0 Comments
30 November 2005
Combining Implicit Evaluation of Objects with Accessing Arrays
It turns out, that while you can preform implicit evaluation of an object, or a variable, or a variable’s associative array members, trying to merge them all has unexpected behavior.
class foo {
var $arr1;
var $arr2;
}
$foo = new foo();
$foo->arr1 = array(5);
$foo->arr2 = array(5);
function accessFirstElement ($object, $property) {
echo $object->$property[0];
}
accessFirstElement ($foo, “arr1″);
In writing this, I would expect PHP to […]

