Jump to content

How To Access The Value Of Var With Constructs Of 1 Class And Printing In Other Class Constructor


ajayshetti

Recommended Posts

<?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

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;

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.