wat does the operator :: use for?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
John.Mike
Forum Newbie
Posts: 18
Joined: Fri Sep 04, 2009 11:43 pm
Location: Canton.China

wat does the operator :: use for?

Post by John.Mike »

hey,fellows ,i got some difficults when i was having the class knowledge of php.
codes belows:
<?php
class A
{
function foo()
{
if (isset($this)) {
echo '$this is defined (';
echo get_class($this);
echo ")\n";
} else {
echo "\$this is not defined.\n";
}
}
}

class B
{
function bar()
{
A::foo();
}
}

$a = new A();
$a->foo();
A::foo();
$b = new B();
$b->bar();
B::bar();
?>


it's an example on php.net....i am wondering wat does the opereator "::" means by ? would anyone give me a hand?
dsainteclaire
Forum Newbie
Posts: 5
Joined: Fri Aug 28, 2009 2:38 pm

Re: wat does the operator :: use for?

Post by dsainteclaire »

You really could easily have searched on the php.net to determine that what you're looking for is the scope resolution operator that lets you call methods of classes outside the class you're currently in, without inheriting the method. Here is the detail for what you're looking for.

http://us3.php.net/manual/en/keyword.pa ... otayim.php

It should provide enough examples to clearly explain how and when to use it. 8)
John.Mike
Forum Newbie
Posts: 18
Joined: Fri Sep 04, 2009 11:43 pm
Location: Canton.China

Re: wat does the operator :: use for?

Post by John.Mike »

got it,it seems that case variables needn't to be changed ,we can use the "A::example()"solution to run the function in the class defined before.tks.
User avatar
Darhazer
DevNet Resident
Posts: 1011
Joined: Thu May 14, 2009 3:00 pm
Location: HellCity, Bulgaria

Re: wat does the operator :: use for?

Post by Darhazer »

You should not use A::example(), if example() is not declared a static method, or you are not in a class that extends A
Post Reply