Re: [PHP] Does this seem wrong to anyone else?
How about this one? function recursive_mkdir($dir) { if (is_dir($dir)) return true; if (recursive_mkdir(dirname($dir))) return @mkdir($dir); return false; } On Thu, Aug 21, 2008 at 1:04 AM, Ashley Sheridan [EMAIL PROTECTED] wrote: Whats even more fun is inheriting somebody elses' *undocumented* code. Oh, and if just happens to be in a strange programming language that you don't know too well, all the better! Sounds awful, but it did happen to me once :-/ Ash www.ashleysheridan.co.uk -- Forwarded message -- From: Jochem Maas [EMAIL PROTECTED] To: Robert Cummings [EMAIL PROTECTED] Date: Thu, 21 Aug 2008 00:52:09 +0200 Subject: Re: [PHP] Does this seem wrong to anyone else? 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 : 1055function mkdir_recursive($pathname, $mode) 1056{ 1057is_dir(dirname($pathname)) || mkdir_recursive(dirname($pathname), $mode); 1058return is_dir($pathname) || @mkdir($pathname, $mode); 1059} The part that bothers me is that mkdir_recursive calls itself from within itself. 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 x.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 x.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 x.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 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Does this seem wrong to anyone else?
Yeti schreef: How about this one? function recursive_mkdir($dir) { if (is_dir($dir)) return true; if (recursive_mkdir(dirname($dir))) return @mkdir($dir); return false; } covers half of one of my gripes about the OP's originally posted function. and it introduces a regression in that file mode is no longer supported. so I'd say it's no better. On Thu, Aug 21, 2008 at 1:04 AM, Ashley Sheridan [EMAIL PROTECTED] wrote: Whats even more fun is inheriting somebody elses' *undocumented* code. Oh, and if just happens to be in a strange programming language that you don't know too well, all the better! Sounds awful, but it did happen to me once :-/ Ash www.ashleysheridan.co.uk -- Forwarded message -- From: Jochem Maas [EMAIL PROTECTED] To: Robert Cummings [EMAIL PROTECTED] Date: Thu, 21 Aug 2008 00:52:09 +0200 Subject: Re: [PHP] Does this seem wrong to anyone else? 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 : 1055function mkdir_recursive($pathname, $mode) 1056{ 1057is_dir(dirname($pathname)) || mkdir_recursive(dirname($pathname), $mode); 1058return is_dir($pathname) || @mkdir($pathname, $mode); 1059} The part that bothers me is that mkdir_recursive calls itself from within itself. 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 x.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 x.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 x.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 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Does this seem wrong to anyone else?
Hi, I am new here.. Hmm, I think what you should add in your function, Yeti, is else - wont it will be for better performance? and not the suppress the error, and Jochem, then it will be perfect - wont it? I am not sure about the else - but as long you provide to the PHP Processor more information - wont it make him be faster? function recursive_mkdir($dir) { if (is_dir($dir)) return true; else { if (recursive_mkdir(dirname($dir))) return @mkdir($dir); return false; } } On Thu, Aug 21, 2008 at 3:42 PM, Jochem Maas [EMAIL PROTECTED] wrote: Yeti schreef: How about this one? function recursive_mkdir($dir) { if (is_dir($dir)) return true; if (recursive_mkdir(dirname($dir))) return @mkdir($dir); return false; } covers half of one of my gripes about the OP's originally posted function. and it introduces a regression in that file mode is no longer supported. so I'd say it's no better. On Thu, Aug 21, 2008 at 1:04 AM, Ashley Sheridan [EMAIL PROTECTED] wrote: Whats even more fun is inheriting somebody elses' *undocumented* code. Oh, and if just happens to be in a strange programming language that you don't know too well, all the better! Sounds awful, but it did happen to me once :-/ Ash www.ashleysheridan.co.uk -- Forwarded message -- From: Jochem Maas [EMAIL PROTECTED] To: Robert Cummings [EMAIL PROTECTED] Date: Thu, 21 Aug 2008 00:52:09 +0200 Subject: Re: [PHP] Does this seem wrong to anyone else? 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 : 1055function mkdir_recursive($pathname, $mode) 1056{ 1057is_dir(dirname($pathname)) || mkdir_recursive(dirname($pathname), $mode); 1058return is_dir($pathname) || @mkdir($pathname, $mode); 1059} The part that bothers me is that mkdir_recursive calls itself from within itself. 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 x.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 x.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 x.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 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Does this seem wrong to anyone else?
daniel danon schreef: Hi, I am new here.. Hmm, I think what you should add in your function, Yeti, is else - wont it will be for better performance? and not the suppress the error, and Jochem, then it will be perfect - wont it? no, see my original critique. and note what Stut said about php5 ... i.e. just use mkdir($dir, $mode, true); I am not sure about the else - but as long you provide to the PHP Processor more information - wont it make him be faster? no. function recursive_mkdir($dir) { if (is_dir($dir)) return true; else { if (recursive_mkdir(dirname($dir))) return @mkdir($dir); return false; } } On Thu, Aug 21, 2008 at 3:42 PM, Jochem Maas [EMAIL PROTECTED] wrote: Yeti schreef: How about this one? function recursive_mkdir($dir) { if (is_dir($dir)) return true; if (recursive_mkdir(dirname($dir))) return @mkdir($dir); return false; } covers half of one of my gripes about the OP's originally posted function. and it introduces a regression in that file mode is no longer supported. so I'd say it's no better. On Thu, Aug 21, 2008 at 1:04 AM, Ashley Sheridan [EMAIL PROTECTED] wrote: Whats even more fun is inheriting somebody elses' *undocumented* code. Oh, and if just happens to be in a strange programming language that you don't know too well, all the better! Sounds awful, but it did happen to me once :-/ Ash www.ashleysheridan.co.uk -- Forwarded message -- From: Jochem Maas [EMAIL PROTECTED] To: Robert Cummings [EMAIL PROTECTED] Date: Thu, 21 Aug 2008 00:52:09 +0200 Subject: Re: [PHP] Does this seem wrong to anyone else? 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 : 1055function mkdir_recursive($pathname, $mode) 1056{ 1057is_dir(dirname($pathname)) || mkdir_recursive(dirname($pathname), $mode); 1058return is_dir($pathname) || @mkdir($pathname, $mode); 1059} The part that bothers me is that mkdir_recursive calls itself from within itself. 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 x.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 x.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 x.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 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Does this seem wrong to anyone else?
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 : 1055function mkdir_recursive($pathname, $mode) 1056{ 1057is_dir(dirname($pathname)) || mkdir_recursive(dirname($pathname), $mode); 1058return is_dir($pathname) || @mkdir($pathname, $mode); 1059} The part that bothers me is that mkdir_recursive calls itself from within itself. 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 x.php on line 1057 Not sure why you're getting that error since it appears to be well defined above... unless x.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 x.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. Cheers, Rob. -- http://www.interjinn.com Application and Templating Framework for PHP -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Does this seem wrong to anyone else?
It's perfectly acceptable to have a function call itself, and one of the first examples in books is a recursive function for factorial numbers, and I've used them on more than one occasion to give directory listings. For the life of me though, I can't understand why it would be giving you the error you're getting from within the function it is meant to be calling. Ash www.ashleysheridan.co.uk ---BeginMessage--- I am debugging someone else¹s code, and this is what they have : 1055function mkdir_recursive($pathname, $mode) 1056{ 1057is_dir(dirname($pathname)) || mkdir_recursive(dirname($pathname), $mode); 1058return is_dir($pathname) || @mkdir($pathname, $mode); 1059} The part that bothers me is that mkdir_recursive calls itself from within itself. 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: Fatal error: Call to undefined function mkdir_recursive() in x.php on line 1057 -- Stephen Johnson c | eh The Lone Coder http://www.thelonecoder.com continuing the struggle against bad code http://www.fortheloveofgeeks.com I¹m a geek and I¹m OK! -- ---End Message--- -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Does this seem wrong to anyone else?
1055function mkdir_recursive($pathname, $mode) 1056{ 1057is_dir(dirname($pathname)) || mkdir_recursive(dirname($pathname), $mode); 1058return is_dir($pathname) || @mkdir($pathname, $mode); 1059} Is this function defined within a class? From which scope do you call this method? Where is the method defined and from where do you call it? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Does this seem wrong to anyone else?
On 20 Aug 2008, at 22:09, Stephen Johnson wrote: I am debugging someone else’s code, and this is what they have : 1055function mkdir_recursive($pathname, $mode) 1056{ 1057is_dir(dirname($pathname)) || mkdir_recursive(dirname($pathname), $mode); 1058return is_dir($pathname) || @mkdir($pathname, $mode); 1059} The part that bothers me is that mkdir_recursive calls itself from within itself. 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: Fatal error: Call to undefined function mkdir_recursive() in x.php on line 1057 It's got recursive in its name so I'd be surprised if it didn't call itself. As for the error I don't really know since the code you've provided clearly defines that function on line 1055. As someone else has mentioned you might want to make sure that x.php is the same file that you've posted the snippet from. If you're using PHP5 then you might be interested to know that the mkdir function supports recursive creation. Check http://php.net/mkdir for details. -Stut -- http://stut.net/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Does this seem wrong to anyone else?
Thanks everyone ... It was a brain fart ... Long bad day today, and I am not paying proper attention ... :) -- Stephen Johnson c | eh The Lone Coder http://www.thelonecoder.com continuing the struggle against bad code http://www.fortheloveofgeeks.com I¹m a geek and I¹m OK! -- -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Does this seem wrong to anyone else?
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 : 1055function mkdir_recursive($pathname, $mode) 1056{ 1057is_dir(dirname($pathname)) || mkdir_recursive(dirname($pathname), $mode); 1058return is_dir($pathname) || @mkdir($pathname, $mode); 1059} The part that bothers me is that mkdir_recursive calls itself from within itself. 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 x.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 x.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 x.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
Re: [PHP] Does this seem wrong to anyone else?
Whats even more fun is inheriting somebody elses' *undocumented* code. Oh, and if just happens to be in a strange programming language that you don't know too well, all the better! Sounds awful, but it did happen to me once :-/ Ash www.ashleysheridan.co.uk ---BeginMessage--- 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 : 1055function mkdir_recursive($pathname, $mode) 1056{ 1057is_dir(dirname($pathname)) || mkdir_recursive(dirname($pathname), $mode); 1058return is_dir($pathname) || @mkdir($pathname, $mode); 1059} The part that bothers me is that mkdir_recursive calls itself from within itself. 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 x.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 x.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 x.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 ---End Message--- -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php