Gregor Kofler Messages: 69 Registered: September 2010
Karma:
Member
Am 2011-01-21 17:51, Leonardo Azpurua meinte:
> Hi,
>
> I have so far used "include" (coming from "C", I just saw it and
> understood it).
>
> Then I read about "require" and "require_once."
>
> Ok. I understand that there might be some situations where not being
> able to reach a particular file might not hinder the execution of an
> applicaton (thus rationalizing the existence of "include"), but I hope
> that will never be my case.
>
> So I will rely on "require" over "include".
>
> So far (I am absolutely new to PHP) I have written reusable functions
> that are stored in files in the include folder, and have not needed to
> nest inclusions.
>
> But now I am going to start coding classes, and if they are going to be
> completely context independent, they must declare their own dependencies
> as "require" statements.
>
> And I guess "require_once" is the natural choice for this situation.
>
> Since I care a lot about simplicity, and lexical simpicity is achieved
> by a vocabulary as reduced as possible, I am about to forget the
> existence of "include", "include_once" and "require".
>
> Is there any chance that such voluntary oblivion will get me into
> trouble later (except for the chance to flunk in a certification test
> that I will never take)?
Perhaps not with thoughtful programming. I only use require_once.
But one could have code like this:
<?php
include 'initcalculation.php';
doCalculation1();
include 'initcalculation.php';
doCalculation2();
....
Looks obnoxious, but I've seen worse PHP scripts. After working through
those, I frequently feel like him [1].