Re: return values from class methods

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 




> Hi, 
> I'm getting confused here. Perhaps someone could point me to an 
> appropriate section of the manual? 
>  
> I have a class defined like so: 
> <?php 
>         class tclass { 
>                 var $mya; 
>                 var $myb; 
>  
>                 function tclass() { 
>                          $this->mya = ""; 
>                          $this->myb = ""; 
>                          } 
>                 function  & squareit($mya) { 

why "&" ??? 

>                          $this->myb = ($this->mya * $this->mya); 

note: $this->mya is different from $mya (the parameter). 
then: $this->myb = 0 everytime.... 

>                          return $this->myb; 
>                          } 
>         } 
> ?> 
>  
> and I'm calling it like this: 
> <?php 
> require('tclass.php'); 
>  
> $myvar = new tclass; 
> $tclass->squareit(11); 
>  
> echo "result is $tclass"; 
> ?> 
>  
> it outputs "result is Object". 
> When I include the function 'squareit' in a script without the oo 
> stuff, I get the result I expect. What am I missing?  
>  

you must do: 
$myvar = new tclass; 

echo "result is " . $tclass->squareit(11); 

remember: an Object is a group for methods (functions) and attributes 
(vars).

                           Jose M. Santibañez A.
                              <jms@nivel5.cl>
                           <http://jms.w.cl/jms>
-------
Pensamiento del Dia:
    Intuicion (s): Un extra~o sexto sentido que le dice a la gente
    que tienen razon, cuando no la tienen.







------------------------ Yahoo! Groups Sponsor --------------------~--> 
$9.95 domain names from Yahoo!. Register anything.
http://us.click.yahoo.com/J8kdrA/y20IAA/yQLSAA/saFolB/TM
--------------------------------------------------------------------~-> 

PHP Data object relational mapping generator - http://www.meta-language.net/ 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/php-objects/

<*> To unsubscribe from this group, send an email to:
    php-objects-unsubscribe@yahoogroups.com

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/
 





[Index of Archives]     [PHP Home]     [PHP Users]     [PHP Soap]     [Kernel Newbies]     [Yosemite]     [Yosemite Campsites]

  Powered by Linux