Re: Re: PEAR installer complains about missing include dir

From: Date: Fri, 14 Feb 2003 21:59:23 +0000
Subject: Re: Re: PEAR installer complains about missing include dir
References: 1 2  Groups: php.pear.general 
Request: Send a blank email to pear-general+get-3766@lists.php.net to get a copy of this message
Christian Dickmann schrieb: >>Current include path : .:/usr/lib/php/:/usr/lib/php/pear/ >>Configured directory : /usr/lib/php > > > "/usr/lib/php/" != "/usr/lib/php" > > Should this be "fixed"? IMO: Yes. Basically, it could be done this way: <?php function canonicalize_path(&$path){ $path = realpath($path); } $pear_path = '/usr/lib/php'; $pear_path_real = $pear_path; canonicalize_path($pear_path_real); $path_sep = (PHP_OS == 'Win32')?(';');(':'); $inc_path = explode($path_sep, ini_get('include_path')); array_walk($inc_path, 'canonicalize_path'); if (! in_array($pear_path_real, $inc_path)){ // Warning -> include_path doesn't include pear_path } else { // All is good -> include_path contains pear_path } ?> Suppose, include_path = '.:/usr/lib/php/pear:/usr/lib/php/../php/' and pear_path like above. First the segment defines a function which calls realpath and saves the result in the parameter passed to it. This is done, so that the function can be used in array_walk(). Next it canonicalizes the $pear_path, so that it'll be the same as the elements of the include_path (after they're canonicalized). After this, it sets $path_sep according to the OS PHP runs on. Or rather, if PHP runs on 'Win32' (or how does PHP call Windows?), it sets $path_sep to ';'. Else it's set to ':'. Now that the path seperator has been determined, the include_path is exploded into an array. Following this, our tiny canonicalize_path() function is called on each of the array elements. Since the canonicalize_path() function modifies the parameter, the $inc_path array will contain all the path elements in a "normal" form. Now we search $inc_path for $pear_path_real. If it cannot be found, a warning should be issued. However, there's one small (?) problem with the code. If include_path contains '.' (like the first element in my original post) and if the cd'ed to $pear_path prior to calling the pear installer and if include_path doesn't contain $pear_path, the fragment will fail. In "code", this will fail: $ cd /usr/lib/php $ # include_path == '.' $ lynx -source http://go-pear.org | php This might be avoided by doing some "pre-cleaning" with reg exps, like so: <?php $pear_path = '.:/usr:.:/:.'; $inc_path = preg_replace("#(^\." . $path_sep . "?)|(" . $path_sep . ":\.)#", "", ini_get('include_path')); ?> Alexander Skwar -- How to quote: http://learn.to/quote (german) http://quote.6x.to (en) Homepage: http://www.iso-top.biz | Jabber: askwar@a-message.de iso-top.biz - Die günstige Art an Linux Distributionen zu kommen

« previous php.pear.general (#3766) next »