faqts : Computers : Programming : Languages : PHP

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

3 of 4 people (75%) answered Yes
Recently 3 of 4 people (75%) answered Yes

Entry

How can you access and set properties or methods from within a class?

Mar 22nd, 2008 21:12
ha mo, Himanshu Jain,


Within a class,you can access a property or method by combining the 
$this variable and the ->operator:
Class point
      {
      //properties
      var $x = 0;
      var $y = 0;
       //constructor
       function point( $x, $y )
               {
                // calling a method
                 $this->moveTo( $x, $y );
                  }
         // method
         function moveTo( $x ,$y)
                 {
                  //setting properties
                  $this->x = $x;
                  $this->y = $y;
                  }
           }
http://www.tantofa.com
http://www.fantofa.com
http://www.mantofa.com
http://www.tanpola.com
http://www.tampola.com
http://www.yamot.com
http://www.mozmar.com
http://www.templatestemp.com