How do you access your data in a class?
I am curious because up-to-now I have always been fond of creating get functions to return data from a class, but I have discovered that Zend are fond of declaring member variables public, and also the creators of
In a simple example:
The class knows precisely what it's getting the parent node of because you're calling the function on the particular node you're working with.
You will also see the same type of thing in Zend Framework whereby public member variables are accessed when retrieving data from a table.
However, particularly in
To give another example of this:
This would of course retrieve the
So now you can see why I am curious. I myself have always preferred using get functions, as aforementioned. Again, it may seem somewhat overkill to create a get function for each and every set function, and also each and every item of data your class holds, but it's certainly possible to create a the magic method
Yet another example:
I suppose it's all down to personal preference, but, as many do when posting to TalkPHP, I myself use the Hungarian notation when coding, and those look especially peculiar when calling a pub member variable. I must admit that whilst I do use Hungarian notation when creating private member variables, I would be hesitant to do when creating their public equivalents.
I would prefer:
So, my question is, my little personal experiment:
Who uses public member variables to retrieve the data, and who creates a multitude of get functions? Would you consider using the
Is there any chance this poll could allow multiple options to be ticked?
Yes, I tried to modify it to be so, but it would appear you can't make it multiple choice once submitted. Huge flaw!
I use the top 2 .... depending on where and how I will be retrieving the data and what the data is that I will be retrieving.
Example for each
Public Member Variables
Almost 99% of all public calls I make are routed into overloading using __get, __set, __isset, __unset which are taken from a registry
I use ind. functions for data I will be calling that is a class property.
Most code I will write does not allow __call overloading
Function When Arguments Required (Methods)
If you are requiring arguments, you will more than likely be performing some kind of logic; you are not really explicitly retrieving data only within the class as it will is likely to be manipulated in some form
|All times are GMT. The time now is 05:55 PM.|
Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0