• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Where to put plain object classes?

#20
(12-27-2014, 05:30 PM)sneakyimp Wrote: * What if a class is only to be used statically. I.e., you NEVER instantiate this class for any reason because all of its methods are static.

It's been my experience that these include/require statements are the source of much code redundancy and many bugs.

Code redundancy and bugs? It's only one line of code. I can live with one redundant line!
I'm curious what kind of bugs you had with include/require you don't have with an autoloader.



(12-27-2014, 05:30 PM)sneakyimp Wrote: * What if you must supply arguments to the constructor for the class? This would in all likelihood cause a fatal error if CodeIgniter tried to instantiate the object without providing these parameters.

You can pass arguments to the loader class in the second parameter:

$params (array) – Optional array of parameters to pass to the loaded library’s constructor

http://www.codeigniter.com/userguide3/li...-reference




(12-27-2014, 05:30 PM)sneakyimp Wrote: * What if I need multiple instances of MyClass to perform some operation.

Then use require_once! Tongue

Maybe I'm too old school, but I don't understand why people have trouble doing simple things just because they use a framework. What would you do in plain PHP? If CI doesn't provide what you're trying to do then do it in plain PHP.
Reply


Messages In This Thread
Where to put plain object classes? - by geekita - 12-02-2014, 05:51 AM
RE: Where to put plain object classes? - by includebeer - 12-27-2014, 07:57 PM
RE: Where to put plain object classes? - by Jamie - 01-06-2015, 05:18 AM
RE: Where to put plain object classes? - by Jamie - 01-06-2015, 03:08 PM

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.