Forum Moderators: coopster

Message Too Old, No Replies

dependency problem when writing php library

do solve it in lib file or app file?

         

Xuefer

2:46 pm on Jul 17, 2003 (gmt 0)

10+ Year Member



lib/a.php:
function a() {
print("hi");
}

lib/b.php:
function b() {
return a();
}

app/app.php:
include('../lib/a.php');
include('../lib/b.php');
a();

now, the question:
do u include("a.php") in lib/b.php or app/app.php?
this is just an example

but when: lib/d.php lib/e.php lib/...php all need lib/a.php
do u include("a.php") in lib/*.php or in app/app.php?

vincevincevince

3:20 pm on Jul 17, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



you use include_once() in everywhere you need it :-)

jatar_k

4:36 pm on Jul 17, 2003 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



I try to set all of my libs up in one file for the site and then include them in the order they need to function.

Similar to your app choice but I would do it this way

libs.php
include "../lib/a.php";
include "../lib/b.php";

then every page on the site can just
include "libs.php";

Then any section or page specific libs can be included individually. It really helps manage libs across large sites and not try to chase a spaghetti mess of nested includes.

Xuefer

5:38 pm on Jul 17, 2003 (gmt 0)

10+ Year Member



thx
that's a pretty good idea :P