0

I have a load of dynamic requires within the code and I was wondering if there was a way to see the php code that was generated as in all the diferent php files put together?

9
  • "Generated" ? Just look at the files and there you have it. Or are you writing php dynamically on a file? Commented Jun 6, 2014 at 14:49
  • Right there is an auto loader to include the class files dynamicaly, I want to see if it is actually including the class file each time new object is called or if it is only including the file once. Commented Jun 6, 2014 at 14:51
  • Well, are you using require/include or require_once/include_once? Are you getting any error like "Cannot redeclare..." Commented Jun 6, 2014 at 14:52
  • It's using require not require_once, I'm trying to prove my point that it should be using require_once to my boss. Commented Jun 6, 2014 at 14:53
  • As you cannot declare a class twice(would result in a fatal) and spl_autoload_* and __autoload are aware of loaded classes it doesn't really matter as long as class autoloading is concerned. *_once on the other side has extra costs, when calling. I assume that was your question. Thats not clear however. Commented Jun 6, 2014 at 14:54

1 Answer 1

1

Answer is based on the clarification in the comments of the question:

Autoloading(spl_autoload_* or __autoload) is only triggered if a class is not yet defined. Using *_once has no real advantage here but bears extra cost. PHP makes sure that the class is only loaded once and (if the loader is correctly implemented and no class includes are done by hand) no fatal is thrown.

If you include classes outside of your autoloader by hand you should still use require_once or include_once as you don't know if that class has been autoloaded yet.

I'll also recommend you to stick to a known structure. There are many correctly implemented autoloaders for the PSR-0 and PSR-4(recommended) standards out there. They have the advantage to be compatible with external libraries and IDEs.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.