what is the meaning of :: in php?

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

ashiland
Forum Newbie
Posts: 18
Joined: Sat Jul 16, 2011 5:19 am

what is the meaning of :: in php?

Post by ashiland »

please explain the codes bellow :

Plugins::init() ;

Rewrite::newInstance()->init();

Session::newInstance()->session_start() ;

many thanks in advance!
User avatar
social_experiment
DevNet Master
Posts: 2793
Joined: Sun Feb 15, 2009 11:08 am
Location: .za

Re: what is the meaning of :: in php?

Post by social_experiment »

It the scope resolution operator.
FriendsofEd PHP Object orientated solutions wrote: It gives access to overridden properties or methods of a parent class.
It is used to call the static methods and properties of a class.
It gives access to class constants .

Code: Select all

<?php
 // calls method init in class Plugins
Plugins::init() ;
?>
Not too sure about the last two :|
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering
ashiland
Forum Newbie
Posts: 18
Joined: Sat Jul 16, 2011 5:19 am

Re: what is the meaning of :: in php?

Post by ashiland »

thanks indeed for your great help!
I didn't even know how it was called otherwise I would have searched for it.
Thanks again.
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: what is the meaning of :: in php?

Post by AbraCadaver »

The Scope Resolution Operator (also called Paamayim Nekudotayim) or in simpler terms, the double colon, is a token that allows access to static, constant, and overridden properties or methods of a class.

The first example is calling the method init() of the Plugins class. In the next two the newInstance() method of the class is being called and this method is returning a new object instance of the class and then the init() and session_start() methods are being called on the new object that was returned using ->.
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
ashiland
Forum Newbie
Posts: 18
Joined: Sat Jul 16, 2011 5:19 am

Re: what is the meaning of :: in php?

Post by ashiland »

Thank you all guys! didn't how helpful could be the forums... getting to know all the nice people around trying to help.
Accurate answer ! many thanks.
ashiland
Forum Newbie
Posts: 18
Joined: Sat Jul 16, 2011 5:19 am

Re: what is the meaning of :: in php?

Post by ashiland »

does anyone know any good source to study classes?
User avatar
social_experiment
DevNet Master
Posts: 2793
Joined: Sun Feb 15, 2009 11:08 am
Location: .za

Re: what is the meaning of :: in php?

Post by social_experiment »

The manual, and a pdf i've read explains classes, how to use them and how to create them pretty well : Friends of Ed, Object Orientated Solutions by David Powers.
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering
ashiland
Forum Newbie
Posts: 18
Joined: Sat Jul 16, 2011 5:19 am

Re: what is the meaning of :: in php?

Post by ashiland »

Is it for free?
ashiland
Forum Newbie
Posts: 18
Joined: Sat Jul 16, 2011 5:19 am

Re: what is the meaning of :: in php?

Post by ashiland »

Hurry up please, I'm desperate to learn the classes.
I just need something simple with a lot of examples
User avatar
social_experiment
DevNet Master
Posts: 2793
Joined: Sun Feb 15, 2009 11:08 am
Location: .za

Re: what is the meaning of :: in php?

Post by social_experiment »

ashiland wrote:I just need something simple with a lot of examples
The php manual contains 'simple' examples which you can use as reference when you create classes. Browse the forum aswell, there are examples (from basic to complex) of classes in various sections.

Code: Select all

<?php
 // from the manual
class foo
{
    function do_foo()
    {
        echo "Doing foo."; 
    }
}

$bar = new foo;
$bar->do_foo();
?> 
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering
ashiland
Forum Newbie
Posts: 18
Joined: Sat Jul 16, 2011 5:19 am

Re: what is the meaning of :: in php?

Post by ashiland »

Thanks social_experiment!
phphelpme
Forum Contributor
Posts: 261
Joined: Sun Nov 21, 2010 3:32 pm

Re: what is the meaning of :: in php?

Post by phphelpme »

Here is something for you to start off with if you are desperate to get hands on:

http://en.wikibooks.org/wiki/PHP_Programming/Classes

Best wishes
ashiland
Forum Newbie
Posts: 18
Joined: Sat Jul 16, 2011 5:19 am

Re: what is the meaning of :: in php?

Post by ashiland »

Thanks again for your prompt reply,
actually I know the basics, I was looking for the more advanced lessons.
sometimes I get stuck when analyzing the things that happen within a piece of code containing classes, as if I know nothing about the classes. That's why I'm looking for a source explaining advanced lessons but in a simply and intelligible way.
phphelpme
Forum Contributor
Posts: 261
Joined: Sun Nov 21, 2010 3:32 pm

Re: what is the meaning of :: in php?

Post by phphelpme »

Then try take a look at this site:

http://www.expertrating.com/courseware/ ... torial.asp

Checkout section/chapter 9 for Advanced Class Concepts

Best wishes
ashiland
Forum Newbie
Posts: 18
Joined: Sat Jul 16, 2011 5:19 am

Re: what is the meaning of :: in php?

Post by ashiland »

sounds great, I didn't know about that website.
I'll start right away and I'll let you know if there's something I don't get.
Thanks for your help.
Regards.
Post Reply