Structure of PHP files

Structure of PHP files

am 23.07.2009 11:36:27 von sandortamas

------=_NextPart_000_0055_01CA0B89.D0893B00
Content-Type: text/plain;
charset="iso-8859-2"
Content-Transfer-Encoding: quoted-printable

Hi,

It isn't really a programming question, but rather a structural.

Let's suppose I have a PHP page, which is built by other PHP files' =
includes.

Which is the better approach:
in a switch-like statement I include the required PHP files, which =
contain all the functions, and the HTML code to provide the =
functionality, or
create a base PHP file which contains all the funcionality, and the =
PHP files only contain calls for these functions, and the HTML code?

I think the previous method gives more control and it is more =
repairable, but the later method gives more modularity. With your =
experiences, what method gives the better overall usability?

Thanks,
SanTa
------=_NextPart_000_0055_01CA0B89.D0893B00--

Re: Structure of PHP files

am 23.07.2009 11:52:32 von dengxule

--00163646c6364f41f2046f5c721a
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable

2009/7/23 S=E1ndor Tam=E1s (HostWare Kft.)

> Hi,
>
> It isn't really a programming question, but rather a structural.
>
> Let's suppose I have a PHP page, which is built by other PHP files'
> includes.
>
> Which is the better approach:
> in a switch-like statement I include the required PHP files, which conta=
in
> all the functions, and the HTML code to provide the functionality, or
> create a base PHP file which contains all the funcionality, and the PHP
> files only contain calls for these functions, and the HTML code?
>
> I think the previous method gives more control and it is more repairable,
> but the later method gives more modularity. With your experiences, what
> method gives the better overall usability?
>
> Thanks,
> SanTa


As far as i experienced, the second method brings problems about the
"REQUIRE".

If you do put classes and functions directly in that "base PHP file", it
will looks fat , and you need a lot of copy/pastes.

If you just put a lot of "requires" in that "base PHP file", you may pay
attention about the PATH. Usage of "__FILE__" or "__autoload" may bring
confusions.

Hoping for the coming of the concept of PACKAGE. Seems that NAMESPACE will
be introduced in PHP6.


Dengxule
09/07/23

--00163646c6364f41f2046f5c721a--

RE: Structure of PHP files

am 23.07.2009 11:59:02 von M.Ford

> -----Original Message-----
> From: Dengxule [mailto:dengxule@gmail.com]
> Sent: 23 July 2009 10:53
>=20
>=20
> Hoping for the coming of the concept of PACKAGE. Seems that
> NAMESPACE will
> be introduced in PHP6.

Already present in 5.3, actually.


Cheers!

Mike
--=20
Mike Ford,
Electronic Information Developer, Libraries and Learning Innovation,
Leeds Metropolitan University, C507, Civic Quarter Campus,=20
Woodhouse Lane, LEEDS,=A0 LS1 3HE,=A0 United Kingdom=20
Email: m.ford@leedsmet.ac.uk=20
Tel: +44 113 812 4730





To view the terms under which this email is distributed, please go to http:=
//disclaimer.leedsmet.ac.uk/email.htm

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: Structure of PHP files

am 23.07.2009 14:47:33 von Floyd Resler

When I first started programming in PHP I used the second method you =20
mentioned. I had a single file I called utils.php and it contained =20
all the functions I could possibly need throughout my site. =20
Unfortunately, this file grew to be over 10,000 lines and most of the =20=

time I only needed a couple of functions for each script I loaded. I =20=

have now abandoned that method and use a more modular approach. I =20
have a lib folder that contains much smaller and specialized scripts =20
(mainly classes). Now I only include what I need. I found it much =20
easier to maintain than having a single file.

Take care,
Floyd

On Jul 23, 2009, at 5:36 AM, S=E1ndor Tam=E1s (HostWare Kft.) wrote:

> Hi,
>
> It isn't really a programming question, but rather a structural.
>
> Let's suppose I have a PHP page, which is built by other PHP files' =20=

> includes.
>
> Which is the better approach:
> in a switch-like statement I include the required PHP files, which =20=

> contain all the functions, and the HTML code to provide the =20
> functionality, or
> create a base PHP file which contains all the funcionality, and the =20=

> PHP files only contain calls for these functions, and the HTML code?
>
> I think the previous method gives more control and it is more =20
> repairable, but the later method gives more modularity. With your =20
> experiences, what method gives the better overall usability?
>
> Thanks,
> SanTa


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: Structure of PHP files

am 23.07.2009 15:34:37 von Robert Cummings

Floyd Resler wrote:
> When I first started programming in PHP I used the second method you
> mentioned. I had a single file I called utils.php and it contained
> all the functions I could possibly need throughout my site.
> Unfortunately, this file grew to be over 10,000 lines and most of the
> time I only needed a couple of functions for each script I loaded. I
> have now abandoned that method and use a more modular approach. I
> have a lib folder that contains much smaller and specialized scripts
> (mainly classes). Now I only include what I need. I found it much
> easier to maintain than having a single file.

Not that I disagree with your methodology at this time, but you could
have just made that single big file, include all those little files and
still had a single load statement in each of your consumer source files.
With compile caches the burden of loading all that code at startup is
rather negligible :)

Cheers,
Rob.
--
http://www.interjinn.com
Application and Templating Framework for PHP

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: Structure of PHP files

am 23.07.2009 15:38:49 von Floyd Resler

'Tis true. I just find dealing with the smaller files much easier.
At the time I was using Komodo IDE and it would get very sluggish with
the larger files.

Take care,
Floyd

On Jul 23, 2009, at 9:34 AM, Robert Cummings wrote:

>
> Floyd Resler wrote:
>> When I first started programming in PHP I used the second method
>> you mentioned. I had a single file I called utils.php and it
>> contained all the functions I could possibly need throughout my
>> site. Unfortunately, this file grew to be over 10,000 lines and
>> most of the time I only needed a couple of functions for each
>> script I loaded. I have now abandoned that method and use a more
>> modular approach. I have a lib folder that contains much smaller
>> and specialized scripts (mainly classes). Now I only include what
>> I need. I found it much easier to maintain than having a single
>> file.
>
> Not that I disagree with your methodology at this time, but you
> could have just made that single big file, include all those little
> files and still had a single load statement in each of your consumer
> source files. With compile caches the burden of loading all that
> code at startup is rather negligible :)
>
> Cheers,
> Rob.
> --
> http://www.interjinn.com
> Application and Templating Framework for PHP
>


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: Structure of PHP files

am 23.07.2009 16:33:37 von Paul M Foster

On Thu, Jul 23, 2009 at 09:34:37AM -0400, Robert Cummings wrote:



> Not that I disagree with your methodology at this time, but you could
> have just made that single big file, include all those little files and
> still had a single load statement in each of your consumer source files.
> With compile caches the burden of loading all that code at startup is
> rather negligible :)

I've heard this before, and I don't understand why people say this. If
you have a 150k file you load before displaying a page, you've still
occupied the CPU with the task of loading a 150k file. What happens to
it afterward (compiling, compressing, caching, whatever) is another
issue. You've still loaded 150k of code. The question is whether you
actually need to load 150k of code from the start. If not, why waste the
resources?

Paul

--
Paul M. Foster

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: Structure of PHP files

am 23.07.2009 16:41:25 von Robert Cummings

Paul M Foster wrote:
> On Thu, Jul 23, 2009 at 09:34:37AM -0400, Robert Cummings wrote:
>
>
>
>> Not that I disagree with your methodology at this time, but you could
>> have just made that single big file, include all those little files and
>> still had a single load statement in each of your consumer source files.
>> With compile caches the burden of loading all that code at startup is
>> rather negligible :)
>
> I've heard this before, and I don't understand why people say this. If
> you have a 150k file you load before displaying a page, you've still
> occupied the CPU with the task of loading a 150k file. What happens to
> it afterward (compiling, compressing, caching, whatever) is another
> issue. You've still loaded 150k of code. The question is whether you
> actually need to load 150k of code from the start. If not, why waste the
> resources?

150k is peanuts and having it already in memory means it doesn't have to
be loaded later. With a compile cache it's quite likely that over time
you'll have the 150k loaded into memory anyways. It's just going to take
longer for it to be loaded since the compile cache has to "encounter" it
first. Once "encountered" it's still occupying the same memory.
Additionally, the operating system does an excellent job of swapping
memory not being accessed regularly (if it needs memory).

Cheers,
Rob.
--
http://www.interjinn.com
Application and Templating Framework for PHP

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: Structure of PHP files

am 24.07.2009 04:45:47 von Lupus Michaelis

Sándor Tamás (HostWare Kft . ) a écrit :
> It isn't really a programming question, but rather a structural.
It is part of our burden ;)

> Which is the better approach:
They are no better approch, only bad ones. I'm using to organize my
code in module. Each module require the needed modules. This design
permit me to ease case testing, and ease maintenance because you know
quite fast what module can be impact by the alteration of another.

I never have to speak about scallability of this method, because I
never work on a very big system. But that's optimization, I think it'll
need some sed (sed -i 's/\/require_ondemand/' project/)
and a strong mecanism to provide including on demand.

--
Mickaël Wolff aka Lupus Michaelis
http://lupusmic.org

Seeking for a position

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php