Need help: how to catch acess of undefined class properties


Posted on 16th Feb 2014 07:03 pm by admin

Hello. I am learning OO with PHP and have hit a problem.
Some code runs as perfectly valid code, where i would like PHP to issue a warning / error.
I guess this is because of the loose typing of PHP, however this cause real bugs go unnoticed in my code and i am looking for a way to be able to detect this.

Did you know?Explore Trending and Topic pages for more stories like this.
The code sample does not produce any warning/error using "error_reporting=E_ALL" with php 5.2.10

Do anyone have a idea or suggestion?

Code: class Objekt
{
var $foo;
var $bar;
}

$x = new Objekt();
$x->foo = 4;
var_dump($x);

$x->baz = 9; //i would like this to cause an warning because "baz" is a undefined property of the Objekt class. but it dont and "baz" is added to the object
var_dump($x);
No comments posted yet

Your Answer:

Login to answer
186 Like 21 Dislike
Previous forums Next forums
Other forums

Load file in PHP
I have 2 files. The first is a PHP generated XML file that's dependent by 2 inputs. The second is a

blank page.... nothing is happening.
I'm new to a lot of this but in the last 24hrs have learned a lot.
Installed latest version of my

Not sure why this script is not working?
Hi I am new to php programing and I was trying to make up a simple script like a captcha but I canno

that old Malformed Headers problem again!!!!! HELP!!!!!!
I've read the http://www.phpfreaks.com/forums/index.php/topic,37442.0.html

I don't think my c

How do i use vars in an array
Hiya peeps!

How do I use a var in an array. You will see $id but it isnt working.


foreach result into a single variable
Hi,

I have this code...

Code: [Select]foreach ($_POST['Interests'] as $interest =&

help with contest script
I would like to code a contest script to my site but i don't know how. Could someone just give me pu

ECC6 - Single sign-on
We are in the process of upgrading to ECC 6 which will support single sign on with user passwords al

Parse String
I need to parse the string below into three variables. How would I do that?

john + 10/20/2008

Dynamically set AccordianPane Header
I have an accordian on my master page. I'd like to be able to dynamically change the header on diff

Sign up to write
Sign up now if you have flare of writing..
Login   |   Register
Follow Us
Indyaspeak @ Facebook Indyaspeak @ Twitter Indyaspeak @ Pinterest RSS



Play Free Quiz and Win Cash