I have just started practicing OO programming using PHP. Recently I have encountered a problem.
I am trying to declare a variable inside a class, but leaving it uninitialized. Later inside a method of the class when I try to initialize the variable it shows the following errors:
Undefined variable: a in C:\wamp\www\sample.php on line 6
Fatal error: Cannot access empty property in C:\wamp\www\sample.php on line 6
Here is the code that I am trying to execute:
<?php
class Sample{
public $a;
function call($b){
$this->$a = $b;
echo $a;
}
}
$sam = new Sample();
$sam->call(5);
?>
How do I fix this?