-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
Description
Q | A |
---|---|
Bug report? | yes |
Feature request? | no |
BC Break report? | no |
RFC? | no |
Symfony version | 3.3.4 |
Hi,
I found that the method Symfony\Component\Cache\Trait\FilesystemCommonTrait::init($namespace, $directory)
has some constructs which prevent the namespacing.
The line 33: if (isset($namespace[0])) { ...
will work only if the given namespace is a string. If it'll be an integer - the isset will return false - and no sub-directory in cache root will be created!
Example:
$x = 892;
echo 'First element: ' . $x[ 0 ] . PHP_EOL;
var_dump( isset( $x[ 0 ] ) );
results in:
First element:
bool(false)
but this notation:
$x = (string)892;
echo 'First element: ' . $x[ 0 ] . PHP_EOL;
var_dump( isset( $x[ 0 ] ) );
returns the correct values:
First element: 8
bool(true)
I would recommend to change the isset directly to a preg_match called one line letter, declare the $match array and check for matching entry in it to throw the exception - or explicitly cast the incoming parameters to string ( it will be obsolete in PHP7 if the method would get typed parameters) .
private function init($namespace, $directory)
{
$namespace = (string)$namespace;
$directory = (string)$directory;
A similar notation can be found also in the line 28, but there is a lower probability to get an integer instead of string. I know that the "isset" is the fastest method to check if a string exists - but in this case it is not the best solution.
Best regards,
Lukas