PHP Fatal error: Cannot access empty property in


Are you trying to access any object’s property (variables/functions) using: $this->$property ?

Check out the red $ should not appear before object properties. In contrast:

<?php
	class A{
		$b = "some value";

		public function get_b(){
			return $this->$b;	// WRONG !!!
		}
	}

	// Using the class

	$myObject = new A();
	echo $myObject-$get_b();	// WRONG!!!
?>

the above code segment is wrong. You should use $ only once – before ‘ this’ only. No need to use $ sign before class variables or methods.

Correct version of the above code segment:

<?php
	class A{
		$b = "some value";

		public function get_b(){
			return $this->b;
		}
	}

	// Using the class

	$myObject = new A();
	echo $myObject-get_b();
?>
Advertisements

4 thoughts on “PHP Fatal error: Cannot access empty property in

    1. Vaia amra jara bangali tader jonno ki kichhu kora jay. Jmon dharabahik tutorial ja webdesign, graphics design, HTML, PHP, CSS, Java Script, Jquery, Linux, ubontu, e.t.c aro koto ki oneke achhe jara ghore boshe kichhur chesta kore, Kintu amader DESHER RAJNOITIK NETA KORMI-der moto ashob jara janen tarao taka chhara kichui bujhena, Tader site gulo shudhu comment r reply er jonno noyto TARA JANEN eta JANANOR BIGGAPON. Michhei desh gorobe tara gorib noyto cripon Uvoyta tei deyar shamortho nai.

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