Jump to content

Passing variables from function-function in class


ChadNomad

Recommended Posts

Hi,

 

I'm still pretty new to OOP and have just started writting my first registration class. Everything is going well except I can't seem to pass a variable from one function to another. For example if in function a() $test = "hello" it won't work if I use it in function b().

 

How do I make them "global"? I don't quite understand the what global vars actually are but apparently it's bad practice and I haven't had much luck in my tests with them. I also only want it to be "global" in the class I've created.

 

Hope that wasn't too confusing!

 

Would $this-> work? <- only just thought of that after posting.

 

Thanks  ;D

Thanks. Function to function is fine now. Still... I'm now trying to use a variable outside of both the function and class.

 

echo $registration->errorString;

 

The above does nothing. I've included the class in an external file. At the bottom of the class file I have:

 

$registration = new Registration();

 

Am I doing something wrong??

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.