is there a strict mode in php?

Ye' old general discussion board. Basically, for everything that isn't covered elsewhere. Come here to shoot the breeze, shoot your mouth off, or whatever suits your fancy.
This forum is not for asking programming related questions.

Moderator: General Moderators

Post Reply
User avatar
yacahuma
Forum Regular
Posts: 870
Joined: Sun Jul 01, 2007 7:11 am

is there a strict mode in php?

Post by yacahuma »

Is there some kind of strict mode in php that does not allow me to reference a non existen data member?

for example if I code something like

Code: Select all

 
$code->data = 'aaa';
 
php does not complain. What exactly php doing? threating it as an array and creating the element dynamically?

for small programs, I dont care, but when code get BIG, little things like this are hard to find.
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Re: is there a strict mode in php?

Post by Chris Corbyn »

This bugs me too. I'm pretty sure that even with error reporting set to E_STRICT PHP does not complain. Try it though:

Code: Select all

<?php error_reporting(E_ALL | E_STRICT); ?>
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Re: is there a strict mode in php?

Post by Benjamin »

You are allowed to add new variables to classes externally and they will be public. You should use get and set methods if you require more control. Have a look at __get() and __set(), where you can add your own code to run checks on variables you are trying to set.
User avatar
yacahuma
Forum Regular
Posts: 870
Joined: Sun Jul 01, 2007 7:11 am

Re: is there a strict mode in php?

Post by yacahuma »

chris

it works
Strict Standards: Creating default object from empty value in D:\Users\oky\htdocs\planillaplus\testm.php on line 10

astions:

I should be using set and get more often. I just always out of time.
Post Reply