Exceptions… wiiee :D
February 7th, 2007
Ok, so this is gonna sound like i’m a complete n00b, but i’ve recently fallen in love with Exception handling in PHP5
.
The reason why i never even looked at it before, is cause i’ve always strived for PHP4 compatibility, but with this latest project (more on it at a later date
), PHP4 has gone out the window
.
As for updates, not much, but i did recently upload a new quick PHP function to Code Yard. It’s called dir_exists(). It’s useful for checking if a directory exists, and if not, it will create it recursively, and return true or false. It works in PHP 4 and 5, in 4 it simply loops to create all required dirs since mkdir() doesn’t support the recursive argument.
Thats it for now, more updates soon, i’ve just been really busy the last few weeks with shit… GRRR
July 23rd, 2008 at 5:01 pm
Actually mkdir() supports recursion!
[code] bool mkdir ( string $pathname [, int $mode [, bool $recursive [, resource $context ]]] )[/code]
July 23rd, 2008 at 7:38 pm
George: Good point. But only in PHP 5.0 and later.
Also, shortly after I wrote the above post, I found a bug in the then current version of PHP 5. Namely, when using mkdir() to recursively create directories, it would always fuckup the permissions on the newly created folders.
The result was that only the system’s root user had access, which makes it useless to a PHP script. Personally I’ve never heard of a production system running Apache under the root user… lol
July 23rd, 2008 at 10:00 pm
I bet your sweet swedish ass that you used mkdir like this:
mkdir(’/path/to/dir’, ‘777′, true);
The second parameter MUST be an integer.
The above line messes up the permissions BIG time.
Instead,
mkdir(’path/to/dir’, 777, true);
will work like a charm, whatever your apache owner is.
Try it
July 23rd, 2008 at 10:02 pm
Owh and btw, neither your codeyard url nor the dir_exist link works
404 hon.
July 23rd, 2008 at 10:41 pm
what?
July 23rd, 2008 at 10:45 pm
Oops, the link URL’s were still relational from the old blog URL. I missed this post when i was updating links after moving
As for the mkdir() function, I’m pretty sure it was a bug with a single release of PHP. Cause I was passing the perms as a integer, and then tried as a string too since the perms went all fucked… lol
Anyway, the point with the dir_exists() function, is that it works in both PHP 4 & 5. It’ll return true/false depending if the directory exists, and if not, there’s a $try_to_create option, which works recursively, in both PHP 4 & 5