Welcome Guest, Not a member yet? Register   Sign In
Use a static method from a personal library without instance
#11

[eluser]Avatar[/eluser]
sweet. That's great news. I've been following this thread for a bit and learned some neat stuff. Thank you guys.
Quote:I read through the loader library and I finally found that, that is possible to load an library without instance it simply with a “false” parameter :
$this->load->library(’mylibrary’,false);
after doing the above I can load static methods?
#12

[eluser]wiredesignz[/eluser]
static libraries are helpers, put them in helpers and load them as helpers

$this->load->library('library', FALSE) still instantiates the library, and passes FALSE to its constructor.

So you now have the class loaded which can be used as a static helper but you also have the object instantiated. Tongue
#13

[eluser]webthink[/eluser]
I'm having trouble understanding people who seem to be suggesting statically loaded library files aren't, and can't be, beneficial. I don't currently have any use for them but I can see where it might be useful and can also see it would address a situation where helpers simply aren't what's called for. This thread is evidence that there are a number of people who would find that functionality useful and I'm sure that's not because they haven't found the 'helper' section of the user guide. Wink
#14

[eluser]wiredesignz[/eluser]
I use a static helper class in Modular Extensions.

Any static class is a helper, its not a library, and in PHP4 you have no static variables so its just another group of functions outside of object context, just like any other helper.
#15

[eluser]wiredesignz[/eluser]
A non instantiated class is static Tongue

It doesn't need a keyword, it just is.
#16

[eluser]Davjack[/eluser]
grrr... you're obstinate ! lol :lol:
#17

[eluser]wiredesignz[/eluser]
So how do you describe it to someone? 'I have this non instantiated library in my application.'

I'm just kidding :lol: Each to his/her own understanding.
#18

[eluser]nmweb[/eluser]
If I use a factory pattern for an ORM or image library I don't need an instance of it in the CI superobject. I want to load it without instantiating it and use $image=image::factory('some_image.gif')->resize('sth'); syntax to instantiate the image object in my variable. For ORM this would be even more important since I might want to share table properties with all my instances of the object whilst only having to query the database once for it. Both cases hardly qualify as helper functions yet have static methods. Yes, you can code around this but it's not neat especially for those who do have php5 for which CI does provide support.

A change like this would not break backwards compatibility but would simply make life easier for some.
#19

[eluser]webthink[/eluser]
I use static helper classes too. That's because I have no need to use them as instantiated libraries but if I did have libraries that contained methods that were in some cases more efficiently used as static functions I would welcome the ability to use them that way. Surely the ability to be flexible in how much resources are consumed when using non core components is in keeping with CI's philosophy.
#20

[eluser]Davjack[/eluser]
[quote author="Davjack" date="1205045628"]I read through the loader library and I finally found that, that is possible to load an library without instance it simply with a "false" parameter :
$this->load->library('mylibrary',false);[/quote]Sorry guys, what I said is false. That's above is not correct. The library is instanced. :-S

[quote author="wiredesignz" date="1205045628"]static libraries are helpers, put them in helpers and load them as helpers...[/quote]I don't agree with you.
First : there is no static libraries, there is static methods.
Second : e.g. for me, a static method like findById(), which return an instanced object, have to be in the library and not in a helper!




Theme © iAndrew 2016 - Forum software by © MyBB