RE: [PHP-DEV] [patch] Late static bindings (LSB)

From: Date: Sat, 22 Sep 2007 00:25:49 +0000
Subject: RE: [PHP-DEV] [patch] Late static bindings (LSB)
References: 1  Groups: php.internals 
Request: Send a blank email to internals+get-32420@lists.php.net to get a copy of this message
>It's becoming messy now - we now need to start to invent all kinds of
>complex propagation rules for it in parallel with the true object
>propagation rules. Why not just have an object then?

Because if you could only see the incredible number of "get_class($this)"
and of "if(__CLASS__!=get_class($this)) do this or that"
and of "$t = get_parent_class($class); return ($t!=__CLASS__ ? $t :
$class)'"
and other special unreadable hacks I have to imagine in order to get what I
want.

Like that one, ridiculous:

static private function getStruct(&$class) {
	if(!(is_array(Entity::$struct) && array_key_exists($class,
Entity::$struct))) {
	eval("if(!isset(".$class."::\$structure))
self::array2xml('".$class."');");
	eval("Entity::\$struct[\$class] = new SimpleXMLElement(
".$class."::\$structure);");
}
return Entity::$struct[$class];
}

Do you understand what it does? Do you find it readable? Clean? I don't.
Yet that's what I have to write in PHP.

And when you have 20 methods in a class, 3 or 4 levels of inheritance, and
you constantly have to manipulate get_parent_class($this) and other
get_class($this) and other eval($class::..), it becomes impossible.

There must be a cleaner way to express what you want to write.
Maybe the problem arises in PHP because, as far as I know, there is no way
to define a function as virtual, like in C++, and so you can't choose
between static lookup or dynamic lookup.


Thread (54 messages)

« previous php.internals (#32420) next »