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

Link to comment
Share on other sites

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??

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.