Brad,
Thanks for your response. I see now that my root problem is that the reading material I have been learning from have been giving me an incomplete idea of the concepts behind things. Do you know what book would be good for learning to write object oriented PHP?
I have some specific questions, too, if you're willing to look at them:
bradgrafelman;10995155 wrote:
Well for one, this method:
function set_session_array() {
// Neither of these makes it work:
$this->session_array = $session_array;
$this->session_array = new ArrayObject();
}
first tries to use an undefined variable $session_array.
The set methods confuse me because if they do not find variables declared within the same class, then I suppose that means those variables need to be passed to them... but I am not calling all of my get methods, and yet they seem to be working (in other scripts). In procedural, if I don't call a function, it does nothing, and if I do not pass the variable in my function call, it does not receive the variable. I guess that methods will receive a property if it is in the class, even if the method is not called anywhere and therefore the variable is not passed to it in a call, but it does have to be put into the parentheses. Is that right? I think I may be unaware of a concept here. If there is something you can say about this that would clarify a concept that would be appreciated.
bradgrafelman;10995155 wrote:
Next, your get_session_array/b method never assigns anything to the session_array property of the object instance. Instead, you use a local variable called $session_array and then do something that doesn't make sense:
return $this->$session_array;
Here, $session_array contains the return value of the call to the method $prepared_statement->fetch(PDO::FETCH_ASSOC). You then try to use that value as the name of a property (e.g. $this->propertyName). Either return the local variable you create inside that method, or first store the value of that local variable in the property that you're almost doing now (just with an erroneous $ in there, I'm guessing).
Oh... Sigh. I hate how a tiny syntax mistake like that can ruin the whole script. I will be a lot more on top of this particular problem of using the $ in front of a property name now that this has been pointed out.
You know, my first attempt at this did return $session_array straight up. However, that results in an object being returned, not the database results I wanted. This is why I switched to trying to assign that data to a property. The way you're wording things is making me suspect that shoving a data array into a property like that and returning it might be considered an awkward way of doing things. However, I cannot seem to get the database data out of this method using the $session_array variable (return $session_array;) - it just outputs a textual representation of my object... So, if you don't mind, which way of doing things is considered most sane, and if it is by using return $session_array; then what concept am I missing here, which is causing my code to return an object instead of the data?