The whole 'why don't you think before asking?' comment was a bit harsh, to say the least. I probably could have emphasized 'more' instead of 'careful', in my earlier post, but I still don't see why people would have to be 'more' careful. Either you're careful about checking to access to undefined properties or you're not.


Quote Originally Posted by bonefry
What are those 'good programming practices' ?
I would say having a class with all the properties defined in the class definition is a good thing.

PHP Code:
  class foo {
     
     public 
$bar 1;
     public 
$baz 2;
     private 
$zaz 3;
     
     } 
Throwing in some phpdoc on top of that is even nicer. However, if I write my code this way, I can't deal with $bar, $baz or $zaz using the __set and __get functionality.

I'm not sure why this is being overlooked. Throwing all accesses to a missing property into one defined array is the only way I've seen it done, but it feels very much like a hack, at best.


Why do you consider __set/__get as poor programming practice ?
What does __set/__get have to do with variable initialization ?
I fail to see it.
See above.

Please provide examples, as we are talking about computer science here and not literature.
What on earth is that 'literature' reference to?

I've worked places what use E_ALL in production just to catch people who don't initialize $foo before looping an array and appending via "$foo.=$bar;". In the strictest sense, that's considered 'bad' because you didn't start by stating $foo=''; to initialize the variable. So, defining and initializing values is (apparently) considered a good thing. But you can't do that in a class definition and still have access to those properties via __get and __set functionality. Not sure what's so difficult to understand here. Apparently quite a lot of people *like* it this way, although it just seems wrong to me.

As someone else pointed out, this is fancy error handling, but it's forcing people in to creating code which would throw errors in the first place (referencing undefined properties) instead of being a more integral part of the object system which allows interception of any property access, defined or undefined.