CodeIgniter Forums
possible error in _ci_load_class code from system//libraries/Loader.php - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Libraries & Helpers (https://forum.codeigniter.com/forumdisplay.php?fid=22)
+--- Thread: possible error in _ci_load_class code from system//libraries/Loader.php (/showthread.php?tid=32040)



possible error in _ci_load_class code from system//libraries/Loader.php - El Forum - 07-11-2010

[eluser]Peter Drinnan[/eluser]
I'm looking at the code for getting the subdir and the use of the implode function doesn't make sense:

$subdir = '';

if (strpos($class, '/') !== FALSE)
{
// explode the path so we can separate the filename from the path
$x = explode('/', $class);

// Reset the $class variable now that we know the actual filename
$class = end($x);

// Kill the filename from the array
unset($x[count($x)-1]);

// Glue the path back together, sans filename
$subdir = implode($x, '/').'/';

}

When using the PHP implode function, the delimiter should be the first parameter and the array the second, but in the code above that is reversed. Is there something I'm missing here or is this an error in the code?

Thanks.


possible error in _ci_load_class code from system//libraries/Loader.php - El Forum - 07-11-2010

[eluser]davidbehler[/eluser]
Code:
$pieces = array('test', 'test2', 'test3');
$glue = ' - ';
        
echo implode(pieces, $glue);
echo '<br/>';
echo implode($glue, $pieces);

I just gave it a try and both give the same result: test - test2 - test3

Maybe this is some undocumented behaviour of the implode function? Don't know. It seems to work as long as one of the parameters is a string and the other is an array. Both being arrays or both being strings doesn't work.


possible error in _ci_load_class code from system//libraries/Loader.php - El Forum - 07-11-2010

[eluser]Peter Drinnan[/eluser]
[quote author="waldmeister" date="1278905835"]

I just gave it a try and both give the same result: test - test2 - test3

Maybe this is some undocumented behaviour of the implode function? Don't know. It seems to work as long as one of the parameters is a string and the other is an array. Both being arrays or both being strings doesn't work.[/quote]


Good to know! I guess that implode PHP function is smart to interpret the field types.


possible error in _ci_load_class code from system//libraries/Loader.php - El Forum - 07-12-2010

[eluser]WanWizard[/eluser]
This behaviour is documented in the PHP manual: "Note: implode() can, for historical reasons, accept its parameters in either order."