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.

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
84 Like 30 Dislike
Previous forums Next forums
Other forums

constructor ?
i have written this program and made 3 constructors in the class and i want to call them in the main

remove a ; from emails in textarea
Code: <?php

session_start();

$database_host = "localhost&qu

PHP url branch??
Functionally, using PHP, I'm doing a test of login input submitted by a user via an html form in a f

On page view, minus credit
Hello all, please, I need a little help with this script. I am charging one credit (credits can be p

styling a RadioButtonList
HiI need to have a radio button and close to it, its lable, then a space then another set of those.

phpMailer not working ..........
HI,
I was playing with the phpMailer script and tried to send a smiple mail using their test scri

Mail from PHP form not always ending up in my inbox?
Hi guys,

I'm a real newbie to PHP and have managed to put together a simple mail form that se

apart from cron
I need to run a php file every one hour. Is there any other solution apart from cron job?

preg_match logical error
Code: <?php
$s = file_get_contents("page.html");
preg_match('/<div cla

I am stumped
OK. Here is what I am trying to do. I have the conditions set, and if the conditions are met, I want

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