Originally Posted by Fou-Lu
Yes and no.
The _once is used to prevent conflict, so it won't attempt to reimport to the symbols table if it already has been (which would throw fatal for anything being redeclared such as functions). But it comes at overhead, so its a tradeoff. I find in OO development, its just far easier to use _once at let it do its thing than to figure out exactly where everything is chaining to my use commands. I haven't a clue what its actually doing under the hood on the use calls though; I've always assumed its the same as issuing a require_once.
I am thinking that what I need to create is some "universal include" - almost like a "bus" - that I include at the top of most of my scripts.
Of course, that is where the problem lies...
If I put something like my Database Connection into some sub-script that I require in every base script, then if I don't need the Database Connection, I have unnecessary overhead.
And if I just put the Database Connection in each sub-script that needs it, then first of all, I may be creating more of a maintenance issue since it is many places, and secondly, if I nest the Database Connection in sub-scripts that need it, I might forget to add it to a parent script which needs it and does NOT require one of the sub-scripts that did have it?!
And that seems to be the idiosyncrasy that I am discovering in my code during my final Unit Testing...
I have scenarios where "script_1" needs "script_2", and "script_2" needs "script_3", but "script_3" refers back to "script_1". (Kinda loopy!!)
I'm probably not making sense, and just not sure how far "down the rabbit hole" I should go with my v2.0 code, since there are likely ways to eliminate this issue with OOP - or better design Procedural Code.
P.S. If anyone is overly interested, I can certainly post some specific code examples...