|
Posted by giacomo.galilei on 09/25/06 20:06
[cut]
> > echo self::foo;
> ^
> ^
> Where is the $ sign here??
My fault.. it's self::$foo of course
[cut]
>
> Not this way. There is only instance of $foo, contained as a static
> member of Kaos. The behaviour you are getting is similar to that in C++
> and Java.
>
> You could have a separate static $foo declared in each class; however,
> this too has limitations.
>
> What exactly do you need this for? i.e. how are you using $foo? There
> may be a more suitable solution to your problem.
>
That's what i have:
there a lot of objects, and each one is located in its own directory
according to this convention:
class file path = 'obj/{$className}/class.{$className}.php'
and i declared the __autoload() function to load any object when
needed.
so i have one function that loads any object, but every object needs to
know where it is located to correctly link its own resources file
(located in its own directory), so i thought to do something like this:
any object extends this:
abstract class Obj
{
static $objpath;
... /* other */ ..
}
function __autoload($classname)
{
$objpath = 'obj/{$classname}/class.{$classname}.php';
require_once( $objpath );
eval( $classname.'::$objpath = $objpath' );
}
so i would like that any object knows where it is, and it knows it by
reading self::$objpath. But i fell in this inconvenience when a parent
object used the directory of its child to take its resource file.
So, the right way is to declare a 'static $objpath' in each class ?
perhaps something more elegant ?
Giacomo
[Back to original message]
|