file_exists and array_merge_clobber
| From: | Lukas Smith | Date: | Tue, 30 Sep 2003 10:32:59 +0000 |
| Subject: | file_exists and array_merge_clobber | ||
| Groups: | php.internals | ||
| Request: | Send a blank email to internals+get-4610@lists.php.net to get a copy of this message | ||
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