So PHP 5.4 came out a little while back, and although there aren’t any major changes, there are a couple to be aware of. Most of the changes involve either very advanced PHP programming (e.g., closures now support the $this variable) or somewhat advanced Object-Oriented Programming. But there are a some changes that will affect the average PHP programmer, which I’ll outline here. Continue Reading…
As part of my [intlink id=”2947″ type=”post”]January-February 2012 downtime[/intlink] (which really turned out to be February-March), I’ve been going through a stack of books, and a virtual stack of ebooks, that I’ve had lying around for way too long. One of the first books from that stack that I read was “Technical Blogging“, by Antonio Cangiano. I bought the ebook through Pragmatic Programmer‘s Black Friday sale back in November, and it’s available through Pragmatic Programmer, or Amazon, of course. Overall, I was quite impressed with the book, and I think it’s going to help me a lot. Before I discuss the book in detail, a quick bit of perspective… Continue Reading…
I’ve just recently become aware of Scott Berkun, thanks to catching an excerpt from his “Confessions of a Public Speaker” book. I’ve since read that book, and it was wonderful (more on that in a separate post). I’m now following Berkun on Twitter, where he frequently Tweets older posts. One of those that I found to be particularly on the nose was “How to Write a Book- the Short, Honest Truth“. I get asked about publishing a lot (and recently had a long email conversation about this, which I’ll also share separately), and thought Berkun’s posting is quite valuable on the subject.
In the post, Berkun distinguishes between three aspects of writing a book:
- Anyone can write a book (i.e., you can write one right now, without needing anything else)
- Getting published (which is a separate issue from writing a book)
- Becoming famous and wealthy
I know there are some people that would like to write a book as an experience, or as a way of sharing what they’ve learned. And some others like the imagined prestige and riches that come with writing a book. I’ve done quite well over the past decade, having written 22 books and sold over 350,000 copies, but I can verify that the prestige and riches aren’t all that you might imagine (I recently discussed the economics in a newsletter). That being said, I’m quite happy that I’m making a decent living doing something that I always dreamed of doing. I’ve been working for myself for 13 years now, which is something.
In any case, if you’re interested in the topic, check out Berkun’s post. It’s short, and well written. At the bottom, you’ll find links to more good articles on writing, if you’re not too discouraged by that point! His “Why You Fail at Writing” is pretty good for helping you accomplish that goal of writing a book.
If you have any questions you’d like to ask me about what it means to be a writer, just let me know!
In this edition…
- About This Newsletter
- On the Web? => Properly Salting Passwords, The Case Against Pepper
- On the Road => Istanbul and Silicon Valley
- On the Blog => My New Logo and Business Card from 99designs
- On the Blog => Five Ways to Lose Work
- On the Blog => Yii and Me (aka, the Yii Book)
- Q&A => How Do I Make Ajax Content Available to Search Engines
- Q&A => Can You Use .html Instead of .php?
- Larry Ullman’s Book News => “PHP 5 Advanced: Visual QuickPro Guide” (3rd Edition)
Every other year or so, I go through the PHP manual. Often I do this in coordination with a book I’m about to write, like now, as I’m writing the [intlink id=”3168″ type=”post”]third edition of my “PHP 5 Advanced” book[/intlink]. Generally, though, I’m a big advocate of re-reading manuals. It’s a great way to correct mistaken thinking you may have, and to learn new and better approaches. For example, I just came across something that had previously slipped past me: the ability to change an array within a foreach loop by passing values by reference.
In versions of PHP prior to 5, in order to change the values of array elements within a loop, you had to do this:
foreach ($array as $key => $value) { $array[$key] = "some updated $value"; }
Just changing the value of $value within that foreach loop had no impact on the actual array element, as the loop only received the value of each array element, not the actual element itself.
This doesn’t come up often—if I need to change the elements in an array, I’m likely to use array_walk(), but it’s nice to know that in PHP 5 you can pass array values by reference in a foreach loop, so that changing the value within the loop actually changes the array:
foreach ($array as &$value) { $value = "some updated $value"; }
As you can see there, prefacing $value by & means that the variable is passed by reference, not by value, just as you’d have in a function parameter.
Again, perhaps this isn’t a life changing thing to learn (okay, it isn’t), but it’s interesting to know. As I continue to work my way through the PHP manual (again!), I’ll continue to share interesting little tidbits I’m finding, or discovering anew.