Reply to Re: Parent Objects

Your name:

Reply:


Posted by raghuanandy@gmail.com on 01/13/07 11:38

Sanders Kaufman wrote:
> Michael Fesser wrote:
> > .oO(Sanders Kaufman)
> >
> >> I read that, but I'm still a little confused.
> >> When I use a class's methods and such, I've been using "->".
> >> But it seems like this "::" is used the same way.
> >> What's the difference?
> >
> > $someObject->method()
> > someClass::staticMethod()
> >
> > '->' requires an instance of a class, whereas '::' is used to call
> > static class methods or constants without having an object. Additionally
> > it's used to call inherited methods.
>
> D'oh!
> I thought I had it - but then you said something about static stuff.
> And I think I'm futzed up about Object v. Class here.
>
> So let's see if I've got it better this way:
>
> I call my OBJECT methods with "->".
> I call my CLASS methods with "::".
>
> Ja?

Right
<?
class A{

public static $a = 'Hello';
public $b ='World';

public function __construct()
{
$this->b = 'Hello World';
}

public function NonStatic()
{
print "\nHere value of b is: ".$this->b;
//Static members can be accessed though within object methods
print "\nA value is: ".self::$a;
}

public static function StaticMethod()
{
print "\n A value is: ".self::$a;

//This will not work, cannot access object variables(members) within
Static methods
//print "\n B value is : ".$this->b;
}
} //end class


$obj1 = new A();

A::StaticMethod();

$obj1->NotStatic();

?>

Hope this clarifes

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация