Re: help with classes
| From: | Joe Conway | Date: | Tue, 13 Feb 2001 05:04:30 +0000 |
| Subject: | Re: help with classes | ||
| References: | 1 2 3 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-39345@lists.php.net to get a copy of this message | ||
> SC>
> SC> That's how you have to do it.
> SC>
> SC>
> SC> class MyClass {
> SC> var $bar;
> SC>
> SC> // This is the class's constructor
> SC> sub MyClass () {
> SC> $this->bar = $foo;
> SC> }
> SC> }
>
> I didn't think php had sub routines like perl? shouldn't that be:
>
> function MyClass(){
> $this->bar = $foo;
> }
>
> I tried this and it does not evaluate the variable. The only way I could
get this to work was to create a function that I can pass the variable to as
one of it paramaters (see previous post)
>
> I could be wrong?
>
Is this closer to what you were looking for?
- Joe
<?PHP
class Foo {
var $bar;
function mymethod(){
global $foo;
$this->bar = $foo;
}
}
$foo = "hello world";
echo "<html><body>";
$cls = new foo();
$cls->mymethod();
echo $cls->bar;
echo "</body></html>";
?>