|
Quicksearch
Calendar
|
Wednesday, July 1. 2009Type hinting for PHP 5.3
For a few years now at work we've been using a patched version of PHP, one those patching featuring type hinting. Over time this proved to be a very handy feature that allows for a much more readable code and introduces a language based validation layer to ensure that the right data types are getting to your functions and methods. It also caught numerous bugs due to functions returning or passing un-expected values. Best of all this feature does not require any changes on the part of opcode caches (essential component for PHP performance) and allows for simple deployment.
I and other people have tried a number of times in the past to introduce type hinting into stock PHP, but unfortunately have never been successful. On a general level most people agree it would be a good idea to have, since it is an optional feature and does not introduce any regressions, heck you can even mix type hinted code with the non-type hinted one. The "PROBLEM" has always been combining of PHP's typeless nature with type hinting, which is where the consensus has been difficult (impossible) to reach. To illustrate the problem let's consider the following: function foo(int $bar) {} Some people would expect that passing "1" (string containing number 1) would be accepted by function foo() and not raise any type errors, since in PHP typically, numbers within strings are considered to be perfectly valid numbers ("1" + "1" == 2). Hence the conflict, some people (I am a part of that group) think that type hinting should be strict, while others think it should be more permissive to be inline with PHP's fluid nature. With introduction of PHP 5.3 and free day in the middle of the week (Happy Canada Day to all Canucks) I've decided to port my internal patch to 5.3 and introduce a new 'feature' to it to hopefully bridge the divide. I've added a IS_NUMERIC (numeric) type hint that allows the script author to designate a parameter as having to be number, meaning input of type boolean, long or float as well as strings containing purely numbers will be accepted. This means if were to rewrite my previous function as: function foo(numeric $bar) {} Then calling foo("112"); would perfectly valid. To further extend basic type hinting support I've also added IS_SCALAR (scalar) type hint that allows a parameter to be designated as scalar, which means it'll accept any boolean, float, string or integer value. The patch is available here: http://ia.gd/patch/type_hint_53.txt I've also posted it to the internals list in the hope of gathering enough support on the part of PHP developers and users to have it added to 5.3 and future releases of PHP. It should be noted that this is not the first idea for type hints, that credit goes to Hannes Magnusson who had posted a similar patch on the internals list back in 2006. Also, back in 2008 Felipe Pena wrote a complete RFC on type hinting with patches and even test. Tuesday, June 30. 2009PHP 5.3 is out!
After over 2 years in development, huge amount of commits and changes PHP 5.3.0 is finally out. Kudos to Lukas M. Smith and Johannes Schlüter who have managed this herculean task and overall have done an excellent job.
There are some really nifty features in this release such as namespaces, closures, mail() logging, a bunch of new extensions and much more. Hopefully, the process of making 5.3 be production ready will be a quick one, as a large amount of testing has already gone into making this release possible. In fact, I be brave enough to say that for non-mission critical environments PHP 5.3 is ready to go as is. Friday, June 19. 2009PHP 5.2.10 Released!
A few hours ago, 11th release of PHP 5.2, 5.2.10 was released to the world. This, as most past 5.2.X releases has been largely focused on bug fixing with quite a few obscure crashes and memory leaks being addressed, in addition to a single security fix in the exif_read_data() function. All in all there are over 100 individual bug fixes in this release and most 5.2.X and definitely all 4.X users should consider upgrading to this version.
The sources and windows binaries for this release can be found at http://www.php.net/downloads.php and the detailed changelog itemizing all of the changes can be seen here. Wednesday, June 10. 2009Ontario Monitor Tax
I was buying 2 monitors for the office today, when a came to paying the bill I discovered a rather nasty surprise. It seems that the Ontario government has decided to apply a $12.03 per monitor recycling tax as part of their EOS program. It looks like our liberal provincial government is always on a look out to grab more of our money, so they can spend it on idiotic initiatives such as eHealth.
Monday, June 8. 2009PHP is 14 Today
Wow, time certainly does fly.
I've started with PHP back in 1997, and A LOT has changed since then in terms of the language's capabilities, user base, and the sheer quantity of sites and applications built on it. Hopefully the next 14 years will bring as many improvements and innovations as the 1st 14 did. Happy B-Day PHP! Wednesday, May 27. 2009
PHP 5.2.10RC1 Released For Testing Posted by Ilia Alshanetsky
in PHP at
20:06
Comments (2) Trackback (1) PHP 5.2.10RC1 Released For Testing
The first release candidate of PHP 5.2.10 was just released and is available for download at:
http://downloads.php.net/ilia/php-5.2.10RC1.tar.bz2 (md5sum: 4ef611fdcf7269b2d372dbdebc504cdb) For windows users, the all manner of binary packages can be found at: http://windows.php.net/qa/ This is a stabilization release with a whole bunch of bug fixes and no new features, so I hope it'll get released quickly. You can help make it happen by testing your code against this RC and reporting any new bugs and/or regressions you come across. Tuesday, April 14. 20095 Letter Domain (ia.gd)
After reading about rev="canonical" and all the hoopla about domain shorteners, I've decided to see how short of a domain I could get for my blog to avoid having people needing to use things like tinyurl etc... to reduce the lengths of URLs. The goal was to get a 2 letter domain with a 2 letter extension, an easy solution seemed to be the .me extension (Montenegro), but alas I could not find a single registrar that would allow a 2 letter domain registration (ia or ai, my initials). It seems most registrars or resellers use generic libraries that no matter what disallow registration of domains <3 characters in length. The reason for this being that most (but not all) registries typically reserve 1 and 2 letter domains. So even when the domains are available, you cannot register them. Fortunately, after some whining on twitter, someone from iWantMyName did some targeted marketing at me
The end result, I am now a happy owner of ia.gd (.gd being the extension for Grenada), it was not particularly cheap $49 as compared to GoDaddy where a common extension can be had for $7-$9 depending on a promotion at the time. However, GoDaddy's domain search system blocks 2 letter domains en-mass, even if they are allowed, so GoDaddy's #fail is iWantMyName #win. Wednesday, March 25. 2009IE8 X-UA-Compatible Rant
A few days ago, Microsoft had done a low-key launch of IE8, which means you need to make your applications compatible with 3 differently broken version of IE ;-P. The biggest challenge IE8 poses is that it runs in "strict" mode by default, which coincidentally breaks all of the previous IE6/7 hacks that had to put in place to make CSS and Javascript render in IE the same way they do in other browsers.
Fortunately, unless you wish to refractor your entire code to support IE8 strictness, MS did add a "compatibility" switch, via the X-UA-Compatible meta-tag or header, if you change its value to "IE=EmulateIE7" it makes it emulate the "strict" mode ala IE7, which at least in all of our code makes it render things properly. However, there is a "slight" problem, which I discovered while trying to implement this function. According to the docs, you can trigger this behavior via the following meta tag: CODE: <meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7" /> , unfortunately it didn't work and according to the IE8's developer tool the default strict mode of IE8 was still being used. No matter the value, be it IE=IE7 or IE5 or EmulateIE7, it would just be ignored. Eventually, I realized that perhaps the DTD is the problem, our pages use XHTML/Transitional DTD, (CODE: <!DOCTYPE html PUBLIC ), which means custom meta tags are effectively spec violations. Which, as far as I can tell IE8 in it's strict mode happily ignores, Catch 22!. This is despite a nice note inside MSDN Blog that says:"-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> CODE: NOTE: The X-UA-Compatible tag and header override any existing DOCTYPE. The solution, is to set the X-UA-Compatible value via an HTTP header ala: PHP: This means the parameter is outside of HTML and will get properly captured by IE, in our case that solved all of the JS and CSS issues that appeared in IE8. For those of you using ExtJS date picker, this does solve the cut-off of the calendar window. Saturday, March 7. 2009I'm on Twitter
At the PHP Quebec conference I've succumbed to peer pressure and decided to sign-up for twitter. So, for those of you interested in following me (damn stalkers
Thursday, March 5. 2009
Common Optimization Mistakes Slides Posted by Ilia Alshanetsky
in PHP, Publications at
20:54
Comments (8) Trackbacks (0) Common Optimization Mistakes Slides
The slides from my PHP Quebec talk on "Common Optimization Mistakes" are now up and can be downloaded from here:
http://ilia.ws/files/phpquebec_2009.pdf I am pretty happy with the talk, which was a bit strange for me, since I get to talk about some of the downside of optimizations, rather then talking about the various specific optimizations. It looked like the audience liked the talk (I hope), so the results seems positive Friday, February 27. 2009PHP 5.2.9 Released!
After a fairly timely (by PHP standards) release cycle the 5.2.9 release is finally out. As usual there are a few security fixes and a fair number (about 50 or so) general bug fixes. All users are encouraged to upgrade to this release, especially so if you are using libxml 2.7 and XML extension, in which case you definitely want to upgrade since this release fixes a CDATA breakage.
Big thanks to all the people who contributed patches and fixes as well as those who took the time to file detailed bug reports that helped issue resolution. We'll see how long it will take 5.2.10 to be released The official release announcement can be found here and the full changelog is available here. Thursday, February 5. 20095.2.9RC1
The first release candidate of 5.2.9 was just released for testing and can be downloaded here:
http://downloads.php.net/ilia/php-5.2.9RC1.tar.bz2 (md5sum: 0252cc45cce713c10e2fae34aa9e406c) I was not planning on 5.2.9 before 5.3 was going to come out, but we've accumulated a fairly high number of bug fixes and a couple of issues with new version of libxml and PHP indicate we need another 5.2 release, so here we are. The release cycle should be pretty quick (I hope) and if all goes well the final will be released before the month is out. Sunday, January 25. 2009
"How to Increase Fuel Mileage ... Posted by Ilia Alshanetsky
in Stuff at
19:18
Comments (7) Trackbacks (0) "How to Increase Fuel Mileage on a Car" - According to WikiHow
In a moment of boredom, yesterday I happen to browse to WikiHow. At the bottom of their site I noticed a rather curios button, advertising that their site is "Carbon Neutral", since this was the first time I've ever seen something like that I was naturally curious, so I clicked the link to learn more. This took me a short article giving a pseudo-scientific calculation of how much carbon is consumed by their site, down to their share of train travel. If you are curious you can find the breakdown here wikiHow:Carbon Neutral. One curios thing I noted was "Jack riding bike to work: 0 lbs of carbon!", last time I checked strenuous physical activity, increases heart rate, which in turn causes the person breathe-in more oxygen and subsequently expel more carbon dioxide. This means that if Jack drove a car, rode a bus or train, he'd actually contribute less carbon to the environment and leave more oxygen for the rest of us
Anyhow, on that page they also had a reference on how/where you can buy "Carbon Credits" to offset impact on the environment, allowing you to equalize your environmental karmic balance or something, what will they come up with next! And best of all it can be done in 7 easy steps, which sounds simple enough for me to follow and actually remember. Step #1 starts with identifying sources of carbon dioxide production in your daily life, ok sounds simple enough. Let's see; mammals those filthy carbon producing critters, need less of'em; gotta eat more of them to save the environment, especially those endangered ones like Tigers and Pandas... mmm... Panda stew... **drool**. Oops, sorry got distracted there for a second... Definitely gotta eat less plants, they actually scrub carbon dioxide and therefor are carbon negative, so no more salad, ok, can do. To all you vegetarians, quit killing the environment by your uncontrolled destruction on carbon reducing greenery and start saving the environment by eating Rhinos, Gazelles, red wolves and spider monkeys, especially the spider monkeys! Step #2 involved cars, first they suggested that I drive less, well that's not gonna happen. Then they tried to wean me off driving entirely, fat chance! You gotta wonder why would they say I should drive less and when I say NO WAY IN HELL, they actually have the audacity to try and convince me to stop driving entirely, completely illogical I tell ya! But, they also had a good suggestion of improving your car's fuel efficiency, which immediately got me interested, I mean save money on expensive gas and save the environment, JACKPOT! So how is that actually done? Apparently there are 26 steps, holy cow! That's like 25 too many for me, but I persevered and read them all anyway, there is nothing I wouldn't do to save mon^H^H^H the environment. The best ones I have decided to share with you all, so you can too do you part to save the environment and for your convenience I've simplified it to 5 easy for consumption ideas, so you don't have to suffer through all 26. 1) Lighten your load. An extra 100 pounds increases fuel consumption by 1-2%. Roger that, no more driving other people or car pooling, those fat bastards can drive their own cars! Making me damage the environment by reducing my fuel efficiency, some people just have no respect for the environment I tell ya. 2) Avoid braking wherever possible. Braking wastes energy from fuel that you have already burned. Good idea, you should start drifting corners, do engine breaking and run lights whenever possible to avoid slowing down and loosing precious inertia & kinetic energy. 3) Tune up your engine. A properly tuned engine maximizes power and can greatly enhance fuel efficiency. Wow, I didn't know that tuning the engine would make it use less fuel. Go and have two stage turbo installed on your car immediately, and get another 300 bhp of environment saving goodness. 4) Learn to watch and predict traffic signals. Stop-and-go driving is wasteful. Useful tip. You should immediately start work on developing telepathy and telekinesis. Since this may take some time, while you are hard at work evolving your mental prowess you can use MIRT that will allow you to control traffic lights without the use of super-powers. 5) Don't circle in a parking lot. Look for a spot in the empty half of the parking lot. This is probably the one I disagree with the most. Basically, to save the environment you need to park in the empty part of the parking lot right near the entrances typically that are typically empty and usually reserved for pregnant women, elderly and the disabled. I suppose to save the environment we all need to make sacrifices, and become heartless environmentalists. I'd like to thank WikiHow folks for all these useful tips and the frigid Canadian winter that inspired this rant... COME BACK GLOBAL WARMING, COME BACK!!!! *** For those of you without sense of humor, possibly lost due to environmental damage, this is a joke Friday, January 9. 2009Mail Logging for PHP 5.3+
I've finally got of my ass and committed my mail logging patch I've written almost 2 years ago. This functionality is predominantly aimed at shared hosters that often have a problem identifying people who abuse the mail() function to send an in-ordinate amount of spam or hacked scripts used for the some purpose.
The logging functionality is disabled by default but can be enabled on a per-directory or globally via 2 INI settings. The mail.log directive allows you to specify the file where each call to mail() will be logged. The log file will contain the path and line # of the calling script in addition to all of the headers indicated by the user. The mail.add_x_header directive will introduce a X-PHP-Originating-Script header that will contain the file name (no path) of the calling script and the uid of the script. This combination should be sufficient for the admin to locate the sending script. The patch should be backwards compatible for PHP 5.2 so those of you who cannot wait for PHP 5.3 can grab it from http://news.php.net/php.cvs/55496 Friday, December 5. 2008PHP 5.2.7 Released
A few hours ago I've concluded a 2 month long release process of PHP 5.2.7 that been over 6 months in the making. Hurrah
The official release announcement can be found here and for those of your bored enough a full change log is also available. As usual a big thanks to all of the developers who has spent the time investigating and fixing bugs and all the folks who reported them as well, especially the ones keep an eye on the security stuff. |
Categories
|
|||||||||||||||||||||||||||||||||||||||||||||||||
