If you have very much experience with writing medium/large PHP based projects, you’ve probably run into the following annoyance:
You have a bunch of classes that you use ubiquitously, some which you wrote and some which others have written. Each file has a single class in it, but since the classes are from difference sources, some of their files have non-consistent naming conventions. You have to include classes into the files which use them, so you might include all of the classes in a header file, but that will cause unnecessary overhead because even unneeded classes get included in ever file which uses the header at all. The other option is to individually include only the necessary classes into the files that use them, but what a pain in the ass!
Fortunately there is a third option, available in PHP 5.0+; it’s called Autoloading Classes. Basically, as soon as an object of a class is created for which the source file has not yet been included a function called __autoload is called. Using that function, we can then include the appropriate class file just before the object is created. Thus avoiding including any additional classes via a header or having to type out extra includes. So how does this magical function work?
Read more…
I wrote a pretty simple PHP function for converting Javascript into a bookmarklet. As you’ll see, it’s nothing too crazy. I did come up with a kind of interesting way of shortening the source using base 64. I don’t know if I’m the first person to do this, but I came up with the idea on my own (no plagiarism!). Unfortunately, it’s not IE compatible.. so there’s a switch to turn that feature off (if you want). Read more…
The idea: Lets say you want to use some service hosted at another site, but there isn’t an API or anything.. just a user-accessible form. Well, in order to use that form, you’re going to have to use something like cURL to submit some POST variables or something to the form handler.
Here’s the problem: What information is actually getting submitted with the form?
The only way to form your curl request is if you know every single bit of data that’s getting sent to the form. You could do this with a tool like the “Web Developer” add-on for Firefox, but then if there’s some onsubmit javascript that affects the form in any way, you don’t get those changes.
My solution: Using javascript, hijack the form and have it submit to a custom URL which will then tell you any variables sent through the headers. Read more…
Something I haven’t talked about a whole lot on here is that I’m actually a professional PHP developer. It’s my job, so usually I don’t mix work and online stuff. This is pretty cool though, so I want people to be able to find it if they’re trying to figure out how to do it. Be warned, if you’re not a PHP coder the following post will make ZERO sense to you
Before I get into what a “reference array” is (I made that term up) let me guide you through the discovery and some practical uses of the theory around references. A while ago I was looking for a way to do something in code that didn’t seem very possible. I wanted to do this:
$var1 = 'Hello World';
echo $"var1";
Problem is, that doesn’t work.. instead I found that you can use variable variables (also known as dynamic variables)
Read more…