I love foreach loops for their simplicity and readability, but they’re a bit quirky when it comes to PHP. Here’s a couple of tips I’ve picked up.
The following are functionally the same:
<?php
$arr = array("one", "two", "three");
reset($arr);
while (list($key, $value) = each($arr)) {
echo "Key: $key; Value: $value
\n";
}
foreach ($arr as $key => $value) {
echo "Key: $key; Value: $value
\n";
}
?>
Ever want to drive straight into a foreach without checking that the array has elements?
<?php
$non_array = null;
foreach ((array) $non_array as $key => $value) {
echo "Key: $key; Value: $value
\n";
}
?>
I just received this email and found it to be the picture of irony. To get you up to speed (I’d never heard of it either), “Crackulous” is an iPhone app that allows people to crack other apps for use on jailbroken iPhones. In short, it’s an app for pirating iPhone apps.
The copyrighted iPhone application Crackulous is hosted on the Localhostr servers at the URL mentioned below. In this instance, said materials are works of the mind and are thus copyrighted as per the Copyright Berne Convention of 1988. Additionally, a copyright notice is displayed to the user both upon obtaining said file, when they start the application for the first time, and in the about screen.
http://localhostr.com/files/1f2de4/crackulous_rev71.zip
My name is Elad Shahar, and I am the lead coder and technical director for the project known as “Crackulous,” and henceforth ask – as per the Digital Millennium Copyright Act Title II: Online Copyright Infringement Liability Limitation Act of 1999 signed into law by President Clinton on October 28th of 1998 – that you please take steps to expeditiously remove or disable access to mentioned materials.
I, Elad Shahar have a good faith belief that use of the copyrighted materials described above on the infringing web pages is not authorized by my registered copyright and by the law. I swear, under penalty of perjury, that the information in the notification is accurate and that I am the copyright owner of an exclusive right that is infringed.
Elad Shahar
[Contact details redacted]
The file named above contains the source code for “Crackulous”. It seems Mr. Shahar AKA SaladFork is ok with his app being used to breach the copyrights of others. The source code is available all over file hosting sites and he’s probably now sending out DMCAs en masse because a public beta of the app has just been released.
I orginally discovered Codeigniter about 18 months ago and I was delighted to find a PHP framework that behaved largely intuitively to me. As I got used to its quirks and adapted it to better suit me, I happened across a forked project called Kohana. Having built a number of applications with Kohana, I have yet to feel the need to modify its default behaviour in any significant way. It just fits well with me.
These features are my favourite benefits of using Kohana over Codeigniter:
- Seperation of system files and static content by default. No extra work is needed to seperate your application files from the framework system files
- Static classes for helpers instead of functions, allowing logical grouping of utility functions.
- Does not break $_GET variables. I don’t care what the CI proponents say, breaking $_GET is unacceptable.
- The session driver can optionally use native sessions. An application on it’s own secure enviroment doesn’t need to worry about native session security like you do on shared servers.
- Supports only PHP5+; PHP4 is dead, and PHP6 is not too far off, it’s time to cast off the dead weight.
There’s plenty more things I like better in Kohana, but the 5 above will have to do for now.
Codeigniter does have one advantage, better documentation, but as Kohana matures so should its documentation.
Back in June simon360 released his dashboard widget for uploading files to localhostr. Earlier this month Mike released a windows desktop app which does much the same. Both of them use mail’s awesome design. They have teamed up and launched a single site that you can get them both from, localhostruploadr.
Currently on my iMac I have a couple of external disks attached that I want to share to the rest of my house. The problem though is that when sharing through Samba I can’t make the shares read only, OS X pretends to accept the permissions change in preferences > sharing, but just changes it right back. After a little bit of poking I’ve got read only shares working.
Open a terminal and replacing {sharename} with the name of the share you set up in Preferences, type:
sudo nano /var/samba/shares/{sharename}
Now append the following line to the end of the file and hit ctrl-o to save.
read only = yes
Finally, reload the Samba config files using this:
sudo /usr/sbin/smbd reload