By using this site you agree to the use of cookies by Brugbart and our partners.

Learn more

Cannot access empty property in ... Error

How to solve a problem with PHP OOP where it fails with this annoying error.

Edited: 2013-04-15 20:18

When working with object oriented php, many developers might bumb into a error like the below:

Cannot access empty property in ...

The eason this happens is most likely due to a miss-placed doller-sign in the code. This can happen to almost anyone who copy-paste a lot of code.

When accessing member properties trough the methods of a class, you might be getting an error saying: "Cannot access empty property in ..." – this may be because you have the following somewhere in your php code:

$this->$username = '';

To get rid of the problem entirely, just remove the doller sign, like shown below:

$this->username = '';

More OOP Tutoials in PHP

  1. Getting started with OOP in PHP