Re: Does this seem wrong to anyone else? | |
| [Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] | |
Robert Cummings schreef:
On Wed, 2008-08-20 at 14:09 -0700, Stephen Johnson wrote:I am debugging someone else¹s code, and this is what they have : 1055 function mkdir_recursive($pathname, $mode) 1056 { 1057 is_dir(dirname($pathname)) || mkdir_recursive(dirname($pathname), $mode); 1058 return is_dir($pathname) || @mkdir($pathname, $mode); 1059 } The part that bothers me is that mkdir_recursive calls itself from withinitself.I am not an expert on this particular type of thing, and maybe that is allowed, but it seems wrong to me, and this error is being generated:That's the point of recursion... to recursively call oneself!Fatal error: Call to undefined function mkdir_recursive() in xxxxx.php on line 1057
the call to mkdir_recursive() on line 1057 is made inside mkdir_recursive() so it's impossible that the function doesn't exist ... unless the function you posted is actually a method of a class, in which case some time in the past the project included a standalone function mkdir_recursive() which is been removed. at least that would be my first/best guess.
Not sure why you're getting that error since it appears to be well defined above... unless xxxxx.php is not the same file in which mkdir_recursive() ha sbeen defined. I'll wager it's not... in which case you need to ensure the file that contains the mkdir_recursive() function declaration is included into xxxxx.php. BTW, FWIW, I wouldn't call the above code good quality since it obfuscates its intent by using || hackishness. It's succinct but less obvious.
it's plain horrid, not to mention using is_dir() & dirname() twice unnecessarily, providing no checks as to whether the path exists and is a file or whether file permissions are okay (if your gonna wrap mkdir() might as well do a proper job) , etc. worst of all the call to mkdir() is error suppressed ... a nice big wtf waiting to happen when it fails. oh and there is absolutely no need to use recursion here, a while loop could be used instead which would be more efficient. lastly Stut pointed out that php5 negates the need for this function altogether, but you might still be stuck on php4 for some reason. ain't it fun inheriting other peoples 'code' ;-)
Cheers, Rob.
-- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[Search] [PHP Home] [Free Matchmaking Site] [Apache Users] [PHP on Windows] [Programming PHP] [Kernel Newbies] [PHP Install] [PHP Classes] [Postgresql] [Postgresql PHP] [PHP Books] [PHP for Windows] [Never a Charge Dating] [PHP Databases] [PHP SOAP] [PHP Books]
![]() |