What is Loader::helper??

Permalink 2 users found helpful
I keep seeing this thingy in the source code of various add-ons and the core and am wondering what this is?

I mean I know in general that it brings in some functionality available in the helper but what exactly is the helper?

Is "Loader::helper" a fancy way of...well...simply including a file?

A class (I can't find no Loader::helper class anywhere), a method (same thing)?

I assume this is an OO PHP construct of some sort. What is it's name? I mean the name of the construct so that I can look up more info about it in the PHP documentation?

Any understanding of this that anyone might care to share would be appreciated.

I looked on Google, in the forum here, and at various source files and it still has me stumped.

Thanks

Carlos

View Replies: View Best Answer
tomreitz replied on at Permalink Reply
tomreitz
Loader::helper is a simple way to include system libraries that help with input validation, UI elements, encodings, feeds, encryption, and more. You can find detailed info about how it all works in the Helpers section of the Developer Guide (http://www.concrete5.org/documentation/developers/).

I believe the Loader class is in /concrete/libraries/loader.php (helper is a method of that class), and most of the libraries you can load with it are in /concrete/helpers/. Hope this helps!
carlos123 replied on at Permalink Reply
Thanks for the input Tom.

Hmm...well now that I have found the code based on your input...what is the Loader::helper construct?

I mean the particular text used as "Loader::helper" with the colons in between.

Is that some sort of Object Oriented PHP way of calling a function within a class and including it's functionality without actually instantiating the class through a New call?

I've tried Googling for "PHP ::", ":: PHP" and 'PHP "::"' to no avail. Nothing.

Carlos
tomreitz replied on at Permalink Best Answer Reply
tomreitz
"Is that some sort of Object Oriented PHP way of calling a function within a class and including it's functionality without actually instantiating the class through a New call?"

Exactly. The "::" is called the scope resolution operator. It basically lets you call a method (or access a member) of a class without having to instantiate it. Read more athttp://us.php.net/manual/en/language.oop5.paamayim-nekudotayim.php....

A quick example:
class Dog {
     public $num_times_barked = 0;
     public function bark() {
          $num_times_barked++;
          print "Dog has barked";
     }
}


After this code:
$fido = new Dog();
$fido->bark();

"Dog has barked" is printed, and $fido->num_times_barked is 1.

But after this code:
Dog::bark();

"Dog has barked" is printed, but there's not really any way to track how many times the dog has barked.

Hope this helps. Happy coding!
carlos123 replied on at Permalink Reply
Thanks so much Tom! That's exactly the kind of input I was looking for.

The good ol' paamayim-nekudotayim LOL. I remember reading about that a while back but couldn't remember the name so as to look it up.

By the way the link to the page describing it at PHP ishttp://php.net/manual/en/language.oop5.paamayim-nekudotayim.php...

Your link didn't work for some reason.

Anyway...thanks again Tom.

Carlos
rijnbow replied on at Permalink Reply
I understand what you mean to say, but $num_times_barked is merely a local variable of bark() -- no matter how you invoke it, its value is not stored either at the class or at the instance ($fido) level.
zanematthew replied on at Permalink Reply
So I take it you have no idea where the "Loader" class is in their "documentation"? I am also finding it hard to find docs and I don't mean "phpdocs", cause thats not really documentation.
jordanlev replied on at Permalink Reply
jordanlev
zanematthew replied on at Permalink Reply
Thanks! :D