PHP provides two built-in functions to retrieve properties of a given class – get_object_vars and get_class_vars. Both these functions behave the same exact way, one taking an object as a variable and the other taking a string class name. The tricky thing about the two functions is that they behave differently depending on the call scope, returning all of the class variables available within the called scope. So if you call either function within the current class you need properties from, all properties are returned – public, protected, and private – because the current scope has access to them all. This makes seemingly simple things like returning all the public properties within the current class a bit of a pain if you want to keep the code inside the class itself.
Read More »
Get Only Public Class Properties for the Current Class in PHP
Why WordPress Should Not Have Won the Open Source CMS Award
Packt Publishing announced the winners for their annual Open Source CMS Award in November, and since then I have been a bit disturbed that the 2009 winner was WordPress. My first reaction was this:
“… So a blogging platform won the content management system award? How sad is that?”
My knee-jerk “how sad is that?” reaction comes not because I don’t think WordPress is worthy, but because of what it implies about the state of other open source CMS projects. The reaction comes from the fact that a blogging platform is kicking your CMS’s ass in its own category.
MySQL Series: Return NULL Values First With Descending Order
Sometimes there are unique situations where you need to order query results by a particular field in descending order, but also need NULL values first. The default (and logical) behavior of MySQL in this case is to return NULL values last, because in descending order they have the lowest value (none). But what if you really need to reverse this and force NULL values to the top of the result set?
Read More »
CodeWorks 2009 Dallas

I was fortunate enough to be selected as the regional speaker for the Dallas CodeWorks 2009 stop by the Dallas PHP User Group through a community voting and selection process. My talk was entitled Object Oriented Apologetics, and was essentially about letting people know what good object-oriented code is, when to use it, how to use it, and more specifically why to use it over traditional procedural PHP code. Read More »
The One Character Block Comment
When debugging, I often find that I have to comment and un-comment a block of code several times during the process of trying to find out what’s going on. That used to mean typing and deleting comment block characters repetitively, but not anymore. Here’s a simple solution to that problem: Comment or un-comment an entire code block of code by typing or deleting a single character.
I was able to arrive at this solution by combining the one-line comment with the comment block in a way that takes advantage of the rules the different types of comments have to follow.
Read More »
OKC PHP User Group Reboot
The local Oklahoma City PHP User Group is re-starting with the okcCoCo as the new venue. The new meetings will be on the second Tuesday of each month, starting with Tuesday, June 09, 2009 at 6:30pm as the first official meeting. Visit the official OKC PHP User Group website to register for meeting reminders and to connect with other local PHP developers.
I will be presenting my talk on Building a Data Mapper with PHP5 and the Standard PHP Library, followed by a discussion on ORMs and whatever else comes up. The presentation will cover all the thought processes, goals, theories, and actual code that goes into building an ORM (or really any other larger project that requires more advance planning). The project that was the basis of this presentation is phpDataMapper – an open-source PHP5 data mapper ORM layer that I started in the fall of 2008. It now powers the model layer of InvoiceMore, a live web application I launched in March 2009.
This is a presentation I have given before at Tulsa TechFest.
jQuery UI Datepicker with AJAX and LiveQuery
I’ve been a little aggravated lately trying to get jQuery UI Datepicker to work correctly on dynamically added fields for creating additional line items to invoices for InvoiceMore. It works great for fields already displayed on the page, but it tends to have major issues with dynamically added fields through AJAX or AHAH. Of course it won’t work out of the box with elements added dynamically to the DOM, so we can use jQuery’s $.live() event (new in 1.3 – you previously had to use liveQuery) to make it work. The Datepicker works by binding to the focus() event by default, but as of jQuery 1.3.2, the ‘focus’ event cannot be monitored by the ‘live’ event function. So we’re stuck with a little work around:
1 2 3 4 5 6 7 | <script type="text/javascript"> $(function(){ $('input.calendarSelectDate').live('click', function() { $(this).datepicker({showOn:'focus'}).focus(); }); }); </script> |
You would think just a simple “$(this).datepicker()” call wrapped inside the live() event would work, but it doesn’t. Turns out that in order to get it working consistently, you have to add the ‘showOn: focus’ config option as well as manually focusing on the element with the focus() event. Charming.
InvoiceMore Launch and Differentiation
InvoiceMore, the startup I have been working on in my spare time for over 7 months, has finally launched. This post actually comes a bit late to the party, because I actually launched InvoiceMore at OpenBeta on March 12, 2009 and blogged about it on the Actridge blog that day. I haven’t even had time to think about sitting down to write this post on my personal blog about the launch until now. That’s a testament to how crazy busy my life has been since I decided to pour all my spare time into starting a business. So what is InvoiceMore, and how is it different?
Mirror Remote Server With Linux FTP Commands
A client of mine called me last night around 8:00pm a little worried. I had recently setup a hosting account for her on my server, so that she would be able to switch from her current FTP-only solution to a full hosting account with a domain and everything for when she makes a webstie in the future (she only needs the FTP to share files for now). On the phone, she said:
The guy who hosts my files just called me. He got in a disagreement with the guy who manages his servers, and told me to back everything up because it might not be there tomorrow
Wow. In a split second, all your data can be gone. The forever kind of gone. The problem was – and the reason she called me – was that she had amassed so many files over the years, that it would take days to backup using her internet connection, and she only had hours to get it done. Okay, relax, I told her – I’ve got it taken care of. I can use linux shell commands to download all the files to my server from yours. It will be much faster, and the files will go directly to the new server instead of having to be re-uploaded there, saving some very time-consuming steps.
Okay, I thought. I’ll just login, make a big tarball of all the files and grab that with my server. But her file hosting account did not allow shell access, and probably didn’t have the extra space for an additional tarball of all the files anyway. So I’m stuck with the linux ftp commands – or so I thought. Turns out, the mget ftp command does not recursively download folders on most servers. So the best function to use on a remote linux server that you can’t run shell commands on is wget, because wget also supports the FTP protocol. The usage goes like this:
1 | wget -r ftp://user:pass@domain.com |
That was going fine, and then the connection was cut-off by the remote server a short way through getting all the files, probably due to some data transfer cap or something. I re-started it, and it cut off again near the same place. So this isn’t enough either, and I still don’t want to do it manually. Luckily, there is a wget flag to ignore already existing files – ‘-nc’. So the whole command to download everything recursively and not re-download files you already have is:
1 | wget -nc -r ftp://user:pass@domain.com |
Remember to back up often. You never know when you might find yourself in a sudden and unexpected data loss situation, like Ma.Gnolia did Friday, January 30th. There’s a good discussion happening on the SitePoint open thread on data loss that same some good backup ideas and methods, too.
Interested in Coworking in Oklahoma?
If you’re in or around the Oklahoma City area doing freelance work, there’s some very good news for you. Derrick Parkhurst along with a few members of the local community are opening OKCCoCo – Oklahoma City Coworking Collaborative. What is Coworking? Coworking is essentially a movement to create a working office environment for freelancers and independent workers that they miss out on working from home. Individuals will be able to rent a desk or private office to work at every month with a bunch or other really cool and smart people instead of working from home or signing a long-term lease for a real office and still being by themselves. If you’re a freelancer or an independent worker that is interested in coworking, you should plan on attending the OPEN HOUSE to view the space on Saturday, January 17th at 2pm. Details and registration are on the OKCCoCo website.
There will be a few additional announcements and activities at the open house, including a speech from Noah Everett, the founder of TwitPic. My own startup InvoiceMore will have a special announcement as well and a bonus for those who sign-up for OKCCoCo with a full or part-time commitment. Come out if you can, and don’t forget to register first! These are exciting times for the Oklahoma technology community!
