In PHP: How to call a $variable inside one function that was defined previously inside another funct

Posted by Sam on Stack Overflow See other posts from Stack Overflow or by Sam
Published on 2010-03-20T15:51:54Z Indexed on 2010/03/20 16:01 UTC
Read the original article Hit count: 114

Filed under:
|

I'm just starting with Object Oriented PHP and I have the following issue:

I have a class that contains a function that contains a certain script. I need to call a variable located in that script within another function further down the same class.

For example:

class helloWorld {

function sayHello() {
     echo "Hello";
     $var = "World";
}

function sayWorld() {
     echo $var;
}


}

in the above example I want to call $var which is a variable that was defined inside a previous function. This doesn't work though, so how can I do this?

© Stack Overflow or respective owner

Related posts about php

Related posts about function