The directory F:\PHP is used to store php file in my computer, I make a new directory named 'lib' in it to store some applications.
Code: Select all
F:\PHP
|--lib
|-- A.php
|-- Facade.php
|--Client.phpCode: Select all
<?php
class A {
public function methodA() {
echo "A::methodA()" . "\n";
}
}
?>Code: Select all
<?php
echo "Current Work Directory is: " . getCWD() . "\n";
require_once('./lib/A.php');
class Facade {
private $a;
public function Facade() {
$this->a = new A();
}
public function show() {
$this->a->methodA();
}
}
?>
Code: Select all
<?php
echo "<h1>Current Work Directory is " . getcwd() . "</h1>\n";
require_once('./lib/Facade.php');
$facade = new Facade();
$facade->show();
?>
Code: Select all
F:\PHP>php -f client.phpCode: Select all
F:\>php -f PHP\client.phpWhat's more, If somebody copies my application(Facade.php and A.php) to his directory named 'library', he will have to modify the Facade.php (modify require_once). I don't want to my client programmer or myself do that. Once something was copied to 'lib', every client programmer can directly use them without any modification. How can I implement that.
Now, my resolution is to force files' location: .php used to provide algorithm must be in 'lib' directory; .php used to show HTML must be in site's root directory. End users should not access something in 'lib', they access files that is in site's root directory, so the current work directory is always site's root. I don't think that is a good resolution.
In Java, .jar files is very convenient, I don't need to modify any code in it. Does PHP have some technic homogeneously.
Thanks!