PHP obscure code:

Can someone explain the logic:

——test1.php————-
class A {
var $a =’ABCD’;
}
class B {
function __construct(){
$x = ‘a’;
$obj = new A();
echo $obj->$x;
}
}
$bobj = new B();

——test1.php————-

Output of test1.php : ABCD

So we have to call add() function first and then we have to call show()..

——test2.php————-

$one = 0;
function add($x,$y){
global $one;
$one = $x+$y;
function show(){
global $one;
echo $one;
}
}

add(10,20);
show();
——test2.php————-
how function are stored in memory and global variable ?

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s