ZF-7271: ZF is not tolerant of phar paths

Issue Type: Bug Created: 2009-07-14T12:46:16.000+0000 Last Updated: 2010-02-04T08:23:17.000+0000 Status: Resolved Fix version(s): - 1.10.1 (10/Feb/10)

Reporter: Clay Loveless (clay) Assignee: Matthew Weier O'Phinney (matthew) Tags: Related issues: Attachments:


A number of ZF components, including Zend_Loader and Zend_Tool_Framework_Loader_IncludePathLoader, are not tolerant of the new PHP 5.3 phar:// paths.

Zend_Tool_Framework_Loader_IncludePathLoader::_getFiles() example:

<pre class="literal">
$paths = explode(PATH_SEPARATOR, get_include_path());

An include path of 'phar://foo/bar.phar:.:/usr/lib/php' will result in $paths looking like this:

<pre class="literal">
    [0] => phar
    [1] => //foo/bar.phar
    [2] => .
    [3] => /usr/lib/php

For ZF to support environments where phars are used in the include path, we may no longer explode on PATH_SEPARATOR. Instead, we now need to step through the include_path string more carefully, like this:

<pre class="literal">
// step through inc path, beware of phar://
$incpath = get_include_path();
$paths = array();
$offset = 0;
while ($pos = strpos($incpath, ':', $offset)) {
    $chunk = substr($incpath, 0, $pos);
    if ($chunk == 'phar') {
    $offset = 0;
    $paths[] = $chunk;
    $incpath = substr($incpath, $pos+1);

// catch the last one which no longer has 
if (! empty($incpath)) {
    $paths[] = $incpath;
unset($incpath, $offset, $chunk);

That results in $paths looking like this:

<pre class="literal">
    [0] => <a>phar://foo/bar.phar</a>
    [1] => .
    [2] => /usr/lib/php


Posted by Clay Loveless (clay) on 2009-07-14T12:58:36.000+0000

Updated suggested fix to populate $incpath variable.

Posted by Matthew Weier O'Phinney (matthew) on 2009-07-14T14:13:08.000+0000

Clay -- I'd be thrilled if you would provide a patch and/or commit a fix. :) Be my guest. :)

Posted by Benjamin Eberlei (beberlei) on 2010-01-24T10:51:23.000+0000

I think this method should go onto Zend_Loader, plus it can be hugely simplified, for example:

<pre class="highlight">
if (strpos($path, "phar://") !== false) {
    $path = str_replace("phar://", "phar#//", $path);
    $paths = explode(PATH_SEPARATOR, $path);
    foreach ($paths AS $k => $v) {
        $paths[$k] = str_replace("phar#//", "phar://", $paths[$k]);

Posted by Matthew Weier O'Phinney (matthew) on 2010-02-04T05:43:52.000+0000

Actually, searching for phar:// is a bit short-sighted; we really should honor all stream definitions in the path as well.

Posted by Dolf Schimmel (Freeaqingme) (freak) on 2010-02-04T05:47:39.000+0000

Assuming there are no directories ending on :// you could probably use the same patch?

<pre class="highlight">if (strpos($path, '://') !== false) {
    $path = str_replace('://', "#//", $path);
    $paths = explode(PATH_SEPARATOR, $path);
    foreach ($paths AS $k => $v) {
        $paths[$k] = str_replace('#//', '://', $paths[$k]);

(code untested, spur of mind)

Posted by Matthew Weier O'Phinney (matthew) on 2010-02-04T08:22:53.000+0000

The behavior was not just phar related, but affected any stream scheme registered in the include_path.

I believe this is now working in trunk and the 1.10 release branch as of r20904; please test.

Have you found an issue?

See the Overview section for more details.


© 2006-2018 by Zend, a Rogue Wave Company. Made with by awesome contributors.

This website is built using zend-expressive and it runs on PHP 7.