PHP
Casting arrays as objects (and vice-versa) in PHP
I just learned that it's possible to cast an associative array as an object in PHP.
It works the other way, too—an object can be cast as an array.
This is especially useful when working with the results of database queries. A lot of codebases seem unsure whether to treat database rows as arrays, or as objects. In these environments, it's likely that you'll get one type as the return value from a particular method, but need to pass the other type as an argument to a second method.
So it's nice to have a simple and language-native way to convert between the two. Some simple demo code:
<?php // create an array $array = array( 'prop1' => 'value1', 'prop2' => 'value2' ); // cast it to an object $object = (object) $array; echo 'The value of the property prop1 is: ' . $object->prop1 . '<br />'; echo 'The value of the property prop2 is: ' . $object->prop2 . '<br />'; // cast it back to an array $array2 = (array) $object; echo 'The value for the key prop1 is: ' . $array2['prop1'] . '<br />'; echo 'The value for the key prop2 is: ' . $array2['prop2'] . '<br />'; ?>
Hiding Wordpress page links
When developing a custom Wordpress theme, it's necessary to provide prev/next navigation wherever there might be more than one page of posts: the main index, search results pages, and archive pages, for example.
posts_nav_link() provides the simplest way to do this—it automatically displays either or both of the links, as needed. If you need more control over the markup, next_posts_link() and previous_posts_link() let you display them independently.
Password Security for Web Applications 101
User registration and login is a standard feature on interactive Web sites, and passwords are the standard way to protect those accounts. But a password is only effective as long as it's kept secret—and you might not be doing everything you can to protect yours.
Let's say you've finished building the HTML and the server-side validation code for your registration form, and you're now ready to write the code which stores the user's information (probably in a database). How should you handle the password?
PECL DLLs
After searching high and low for a DLL version of the PDFLib PECL extension (pecl4win.php.net is down, and apparently has been for a while), I stumbled across this blog post, which offers ZIP files of both thread-safe and non-thread-safe versions of all PECL DLLs.