I'd like to combine some static variables but can't get any of the following to work:
class tableNaming{
private static $MYTABLES_PRE = 'me_';
private static $users_table = $MYTABLES_PRE . 'users';
}
class tableNaming2{
private static $MYTABLES_PRE = 'me_';
private static $users_table = self::$MYTABLES_PRE . 'users';
}
class tableNaming3{
private static $MYTABLES_PRE = 'me_';
private static $users_table = tableNaming3::$MYTABLES_PRE . 'users';
}
class tableNaming4{
private static $MYTABLES_PRE = 'me_';
private static $users_table = $this->$MYTABLES_PRE . 'users';
}
class tableNaming5{
private static $MYTABLES_PRE = 'me_';
private static $users_table = self::getMyTables() . 'users'; // try line below as well
// private static $users_table = $this->getMyTables() . 'users'; // tried both
public static function getMyTables(){ return self::$MYTABLES_PRE; }
}
any ideas? I really thought #5 would work (it's the one I like the least though)
thanks for the help, this is really ruining my night.Unfortunately, you can't initialise static variables with anything that requires evaluating an expression. (certainly #4 wouldn't work, for obvious reasons).
It brassed me off enough to come up with this solution (<!-- m --><a class="postlink" href="http://www.phpbuilder.com/board/showthread.php?p=10627465#post10627465">http://www.phpbuilder.com/board/showthr ... st10627465</a><!-- m -->).thanks for the link. I came up had a similar idea as i was trying to fall asleep last night.
I appreciate it.your fucntion
class t1{
public static function static__construct(){ }
}
do I have to call this? Or by referencing anything else in the class, will it be called (and thus instantiate my variables)?Yes, you will need to call it before the class is usable. (Note that in the code I gave the call is immediately after the class definition, so that it is guaranteed to be run when the class is loaded. But it can go anywhere just so long as it is called at some point before using the class.)
class tableNaming{
private static $MYTABLES_PRE = 'me_';
private static $users_table = $MYTABLES_PRE . 'users';
}
class tableNaming2{
private static $MYTABLES_PRE = 'me_';
private static $users_table = self::$MYTABLES_PRE . 'users';
}
class tableNaming3{
private static $MYTABLES_PRE = 'me_';
private static $users_table = tableNaming3::$MYTABLES_PRE . 'users';
}
class tableNaming4{
private static $MYTABLES_PRE = 'me_';
private static $users_table = $this->$MYTABLES_PRE . 'users';
}
class tableNaming5{
private static $MYTABLES_PRE = 'me_';
private static $users_table = self::getMyTables() . 'users'; // try line below as well
// private static $users_table = $this->getMyTables() . 'users'; // tried both
public static function getMyTables(){ return self::$MYTABLES_PRE; }
}
any ideas? I really thought #5 would work (it's the one I like the least though)
thanks for the help, this is really ruining my night.Unfortunately, you can't initialise static variables with anything that requires evaluating an expression. (certainly #4 wouldn't work, for obvious reasons).
It brassed me off enough to come up with this solution (<!-- m --><a class="postlink" href="http://www.phpbuilder.com/board/showthread.php?p=10627465#post10627465">http://www.phpbuilder.com/board/showthr ... st10627465</a><!-- m -->).thanks for the link. I came up had a similar idea as i was trying to fall asleep last night.
I appreciate it.your fucntion
class t1{
public static function static__construct(){ }
}
do I have to call this? Or by referencing anything else in the class, will it be called (and thus instantiate my variables)?Yes, you will need to call it before the class is usable. (Note that in the code I gave the call is immediately after the class definition, so that it is guaranteed to be run when the class is loaded. But it can go anywhere just so long as it is called at some point before using the class.)