Hi,
We have a new intern who got right to work to improve file_exists()
to
also be able to check the include_path similar to how fopen()
can.
We have a patch here.
Due to some issues on the CVS version of ext/standard/filestat.c in HEAD
we commented out some code in the file in order to be able to compile.
This is not really needed for our patch of course.
You can find the patch here:
http://www.backendmedia.com/php_patches/file_exists.patch
Since neither my intern nor I have previous experience in modifying the
PHP source we would obviously appreciate any hints. We were especially
unsure how much we need to check the parameter values ourselves.
We also plan to create a new array function based on a user suggestion
in the user comments of array_merge_recursive()
.
Here is an implementation in PHP (I modified it a bit this morning
without testing it in much detail, so hopefully it works as I have
planned it). Essentially I need this in a bunch of PEAR classes to be
able to handle multidimensional option arrays that need to overwrite a
default array.
function array_merge_clobber($a1, $a2)
{
if (!is_array($a1) || !is_array($a2)) {
return false;
}
foreach($a2 as $key => $val) {
if (is_array($val) &&
isset($a1[$key]) &&
is_array($a1[$key])
) {
$a1[$key] = array_merge_clobber($a1[$key], $val);
} else {
$a1[$key] = $val;
}
}
return $a1;
}
Dunno if the name is all that good though :-)
regards,
Lukas Smith
smith@backendmedia.com
BackendMedia
www.backendmedia.com
berlin@backendmedia.com
Linn Zwoch Smith GbR
Pariser Str. 44
D-10707 Berlin
Tel +49 30 83 22 50 00
Fax +49 30 83 22 50 07
Using the include path for file_exists doesn't sound useful to me, for
similar reasons as those for not allowing to write a file in the include
path - which file are you actually writing to? What if someone puts a file
with the same name earlier in the include path and so on.
What is probably better is some kind of generic path-searching function that
returns the full path to the first file in the include_path (or some other
path).
--Wez.
----- Original Message -----
From: "Lukas Smith" smith@backendmedia.com
To: internals@lists.php.net
Sent: Tuesday, September 30, 2003 11:32 AM
Subject: [PHP-DEV] file_exists and array_merge_clobber
Hi,
We have a new intern who got right to work to improve
file_exists()
to
also be able to check the include_path similar to howfopen()
can.
I agree with Wez, what if you are searching for a file with a relative file
path, e.g:
<?php
if (file_exists("somefile.php"))
// ...
would return true if "somefile.php" is not in the current directory but is
in your include path, not what you expected. Besides, you can easily
implement this functionality in php.
-Justin Hannus
"Wez Furlong" wez@thebrainroom.com wrote in message
news:021801c38741$b34407f0$0702a8c0@titan...
Using the include path for file_exists doesn't sound useful to me, for
similar reasons as those for not allowing to write a file in the include
path - which file are you actually writing to? What if someone puts a
file
with the same name earlier in the include path and so on.What is probably better is some kind of generic path-searching function
that
returns the full path to the first file in the include_path (or some other
path).--Wez.
----- Original Message -----
From: "Lukas Smith" smith@backendmedia.com
To: internals@lists.php.net
Sent: Tuesday, September 30, 2003 11:32 AM
Subject: [PHP-DEV] file_exists and array_merge_clobberHi,
We have a new intern who got right to work to improve
file_exists()
to
also be able to check the include_path similar to howfopen()
can.
Justin Hannus wrote:
I agree with Wez, what if you are searching for a file with a relative file
path, e.g:<?php
if (file_exists("somefile.php"))
// ...would return true if "somefile.php" is not in the current directory but is
in your include path, not what you expected. Besides, you can easily
implement this functionality in php.
its going to be optional, not mandatory ... but that has already been answered
the whole point about this additional feature is that you can use it to check
for include file existance before the actual include:
if (file_exists("somefile.php", true)) {
include "somefile.php";
}
IMHO this case is common enough so that it deserves a native C implementation
either as an option to file_exists()
or as a seperate function like
file_exists_in_path()
--
Hartmut Holzgraefe <hartmut@php.net
the whole point about this additional feature is that you can use it to
check
for include file existance before the actual include:if (file_exists("somefile.php", true)) {
include "somefile.php";
}IMHO this case is common enough so that it deserves a native C
implementation
either as an option tofile_exists()
or as a seperate function like
file_exists_in_path()
If we're really going to go down this road, why not implement it in a
more generic, reusable way:
file_exists("somefile.php", ini_get('include_path'))
That would give us some additional mileage out of the change.
For the record, I'm -0 on this. I'd be -1 if it wasn't so obviously
optional.
--
Jon Parise (jon@php.net) :: The PHP Project (http://www.php.net/)