Re: [PHP] (Exact) Difference between -> and ::

2002-07-14 Thread Alberto Serra

ðÒÉ×ÅÔ!

Micha wrote:
> Hi,
> 
> I would like to know the exact difference between -> and ::.
> I know that I can use as class directcly by using :: but I still don't
> know the exact meaning
> So why do they use in Example 8 on
> http://www.php.net/source.php?url=/zend2_example.phps $this->id =
> self::$id++ and not self::id++ or $this->id++ ... ?
> 

Some OO languages (notably smalltalk does it) name a difference between 
Class methods (and variables) and instance variables. What is "class" 
can be used and executed even when lacking any actual instance of the 
class.

PHP has not fully implemented this model (we miss class variables, that 
is, a value that is common and general to all instances of a given 
class) but does have a bit of it.

So :: is mainly used to execute a method without needing to create an 
instance for it. If your class "Printer" has a method 
"changeCartridge()" you can use Printer::changeCartridge() without the 
need of any prior
$myPrinter = new Printer()

That is, you use a class as a common library. This has a limitation in 
that you cannot dinamically say $myclass::changeCartridge(), while you 
can say:

$a = "printer";
$p = new $a();
$p->changeCartridge();

The operator :: cannot address internal variables directly like -> does 
for the simple reason that no variable exists, in the absence of the 
instance. Which is why you declare $ signs. :: operator is also handy 
when you need to call an overriden method. By saying parent::myMethod() 
you call your parent's method, while $this->myMethod would execute the 
locally redeclared code.

-> operator can be read (maybe it must be read, I don't know) as 
"belongs to". So "this->a" means "the $a that belongs to $this" (the 
object in which you are executing class code). -> obviously only applies 
to single instances and not to classes.

Hope it was clear.


ÐÏËÁ
áÌØÂÅÒÔÏ
ëÉÅ×


@-_=}{=_-@-_=}{=_-@-_=}{=_-@-_=}{=_-@-_=}{=_-@-_=}{=_-@-_=}{=_-@

LoRd, CaN yOu HeAr Me, LiKe I'm HeArInG yOu?
lOrD i'M sHiNiNg...
YoU kNoW I AlMoSt LoSt My MiNd, BuT nOw I'm HoMe AnD fReE
tHe TeSt, YeS iT iS
ThE tEsT, yEs It Is
tHe TeSt, YeS iT iS
ThE tEsT, yEs It Is...


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




[PHP] (Exact) Difference between -> and ::

2002-07-14 Thread Micha

Hi,

I would like to know the exact difference between -> and ::.
I know that I can use as class directcly by using :: but I still don't
know the exact meaning
So why do they use in Example 8 on
http://www.php.net/source.php?url=/zend2_example.phps $this->id =
self::$id++ and not self::id++ or $this->id++ ... ?

-micha


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




[PHP] (Exact) Difference between -> and ::

2002-07-14 Thread Micha

Hi,

I would like to know the exact difference between -> and ::.
I know that I can use as class directcly by using :: but I still don't
know the exact meaning
So why do they use in Example 8 on
http://www.php.net/source.php?url=/zend2_example.phps $this->id =
self::$id++ and not self::id++ or $this->id++ ...


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php