Skip to content

Commit 338a2ba

Browse files
committed
Update pitfall trap 2
1 parent 39919a6 commit 338a2ba

File tree

1 file changed

+30
-1
lines changed

1 file changed

+30
-1
lines changed

README.md

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,12 +173,19 @@ Compile it (Oops... one Unknown File Object has not been included)
173173
phpcc -e bin/acme.php -f bin/acme.php -d src/ -o bin/acme
174174
```
175175

176+
##### Problem
177+
176178
Launching the `bin/acme` compiled archive should raise an error because of the missing file.
177179

178180
Well...not. What happens here then ?
179181

180182
If the `bin/acme` compiled archive stays in its place,the `lib/Ufo.php` can still be found from its point of view.
181183

184+
##### Solution
185+
186+
Always move the compiled executable **out** of the project's working directory before testing it.
187+
188+
182189
#### Trap 2: different files with the same relative path
183190

184191
Eg:
@@ -187,7 +194,29 @@ Eg:
187194
require "vendor/autoload.php"
188195
```
189196

190-
TODO: explain, give workaround
197+
Chances are, there might be such a `vendor/autoload.php` file in the project to be compiled.
198+
199+
##### Problem
200+
201+
From the compiled app point of view, `vendor/autoload.php` refers to a relative path in the PHAR archive.
202+
203+
##### Workaround
204+
205+
The phpcc execution dir (i.e the compiled project's top directory) must be added first in the include path.
206+
207+
For example in the main entrypoint script:
208+
209+
```php
210+
// bin/main.php
211+
212+
// ensure we load the execution directory's autoload, not the
213+
// one included in the compiled phar executable
214+
set_include_path(getcwd() . PATH_SEPARATOR . get_include_path());
215+
216+
require 'vendor/autoload.php';
217+
218+
// ...
219+
```
191220

192221
### Size too big
193222

0 commit comments

Comments
 (0)