What is :: in php?

envo

Expert Member
Joined
Jan 14, 2014
Messages
3,265
Reaction score
437
I downloaded a set of tools that's written in PHP but I can't seem to grasp how they did things.

You include the one class and then:

class::load('plugin')

Without instantiating it or anything
then the next line is something like:

plugin::start()

Also without instantiating it first.

I'm trying to use namespaces on it so that I can use my Autoloader script to include it but it's an uphill battle, because if the autoloader loads it, it can't call as above anymore

http://codecri.me/sources/includes/class-xhttp-php/
 
Well, from stackoverflow, it seems to be scope resolution. Though, I always assumed it to mean a call the a static method.

This is another reason why the php language is such a mess. Inconsistency :(
 
I didn't google "double colon" but ::

That's more or less the explanation I got as well, but still doesn't make sense really

I'm assuming that the way the call is is so that you don't have to instantiate it first?

mmm
 
What error/problem are you running into exactly? "::" just generally means you're calling a static function in PHP. You can reference namespaces too: namespace\plugin::start();
 
I have an autoloader that works based on the namespace, so it will load the corresponding class if it needs it.

The abovementioned code written by someone else uses a plugin mechanism themselves:

\MyNamespace\xhttp::load('multi');

Will load the xhttp_multi class

Then if I go

\MyNamespace\xhttp_multi::start();

My autoloader loads the xhttp_multi class again (class_exists is false) and then it errors with redeclare stuff

If I manage to get it to load, it errors within the xhttp class saying that xhttp class isn't defined or something.

Thinking I shouldn't try namespacing it and exclude it entirely from my autoloader
 
So if I create objects of the class instead it might work? Will see, maybe I'll just email the creator or just pull it out of the autoloader and physically include it. only need it in one spot
 
Allows you to reference objects in other classes

and primitives and methods


a special operator to access static members and accessing overridden method.... php, what a dog show........
 
And the big problem I find is that developers do not know when to implement the use of "::", when to use the Singleton pattern and when to use a factory pattern.

I'm currently banging my head at work with code that is calling an entire class methods statically instead of using the factory pattern which the developer was suppose to do.
 
Top
Sign up to the MyBroadband newsletter
X