CapIsland CapIsland - 7 months ago 38
PHP Question

php autoload variable class name

Can anyone explain how this works:


in the answer of this stackoverflow question:

error when using variable class name and static method


It does the same as:

${0}=$variable->other['class'];//value here lets say is 'myClass'
${0}::my_static_method();//here now is myClass::my_static_method(); called

Why is (int)! used? Because he just tricks around.

Result of print (int)!${0}=$variable->other['class']; is 0.

Because if anything is set here ${0}=$variable->other['class'],

print (bool)${0}=$variable->other['class']; will be true.

Then it will be negated via !, so it becomes false and with (int) finally 0.

And thats the name of the variable that was set before: ${0}.

But it is very bad practise to give an global variable just an number.

Normaly all variables MUST start with _ or A-Za-z.

Dont know why its droped as example, maybe to make fun of the people.

Dont use this at all!

Just to show how its not done ;) (working code)

define(0x7F,' ..the crazy Girl');
define('§','at? ');
define('_',' Wh');
${'$#?!'} = ' Arrr!';
$♂ = Tom;
$♀ = Tina;
$c = get_defined_constants();
print  _  . § . $♂ .' '.  Just . ' ' .  Want . ' ' . To ." ". Lov€ ." ". $♀ . $c[127] . ${'$#?!'};
//result: What? Tom Just Want To Lov€ Tina ..the crazy Girl Arrr!

Feel free to get crazy. :-)