ajayshetti Posted November 2, 2012 Share Posted November 2, 2012 <?php class a { //public $con=10; public function __construct() { $con=10; echo "Class a"; } } class b { public function __construct() { echo "Class b<br>"; $c=new a(); echo "<br>".$c->con; } } $d=new b(); ?> not printing the value of $conn why and how to resolve this issue Quote Link to comment Share on other sites More sharing options...
requinix Posted November 2, 2012 Share Posted November 2, 2012 1. Because you commented out the declaration of the variable. 2. Because when you assigned con=10 you didn't use $this. Which you must do. $this->con = 10; Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.