note 32178 modified in function.basename by vrana
| From: | vrana@php.net | Date: | Tue, 17 Aug 2004 14:52:48 +0000 |
| Subject: | note 32178 modified in function.basename by vrana | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-79856@lists.php.net to get a copy of this message | ||
<?php
$foo="/path/to/file.ext";
echo $foo."<br />";
$bar=$foo;
echo basename($bar,".ext")."<br />";
echo $foo."<br />";
echo $bar."<br />";
?>
Will display:
/path/to/file.ext
file
/path/to/file
/path/to/file
Which is probably not expected behavior, as
it returns one thing, changes the variable
to produce something else, and also modifies
BOTH variables in memory.
To avoid this, use:
basename(strval($bar),".ext")
--was--
$foo="/path/to/file.ext";
echo $foo."<br />";
$bar=$foo;
echo basename($bar,".ext")."<br />";
echo $foo."<br />";
echo $bar."<br />";
Will display:
/path/to/file.ext
file
/path/to/file
/path/to/file
Which is probably not expected behavior, as
it returns one thing, changes the variable
to produce something else, and also modifies
BOTH variables in memory.
To avoid this, use:
basename(strval($bar),".ext")
http://php.net/manual/en/function.basename.php