Justtechjobs.com Find a programming school near you






Online Campus Both


php3-list | 199903

Re: [PHP3] Accessing variables created in a class From: Rasmus Lerdorf (rasmus <email protected>)
Date: 03/30/99

> <?
> class myClass{
>
> $myVar = "anyString";
> }
>
> $newObj = new myClass;
>
> print $newObj->myVar; (from manual, cart example; also tried with echo)
>
> ?>
>
> This doesn't send the value of $myVar to the screen. However, if I have an
> echo in the class itself it prints the variable but for real world use I
> would want to be able to print the variable at any time.
>
> What am I missing. The example in the manual is a little different in that
> the variable was set from outside of the class, so to speak. What is the
> solution?

Your syntax is off. Use:

 class myClass {
   var $myVar = "anyString";
 }
 print $newObj->myVar;

-Rasmus

--
PHP 3 Mailing List   http://www.php.net/
To unsubscribe send an empty message to php3-unsubscribe <email protected>
To subscribe to the digest list:  php3-digest-subscribe <email protected>
For help: php3-help <email protected>  Archive:  http://www.php.net/mailsearch.php3
List administrator:  zeev-list-admin <email protected>