BlogPhotosContact

Topics

Is Planet PHP still maintained ?

I've started a new blog where I plan to post some contents about PHP, HTML_QuickForm2 and some other stuff I work on, and I have asked the Planet PHP maintainers to aggregate my PHP feed, but two weeks later, I still haven't had a reply from them. So if anyone knows who I should contact, please let me know.

My new blog can be found here :
http://mansion.im
The PHP feed is more specifically here :
http://mansion.im/category/php/feed/
Also, you might want to let the Planet PHP developers that their site looks broken today, probably because of a problem with a feed.
See http://www.planet-php.net/
Thanks.
Comments (12)  Permalink

Paamayim Nekudotayim p0wnd!

Yeah I know, I am rancorous... :)
Paamayim Nekudotayim p0wnd
Back in 2002, I asked php-internals for support of $c = "classname"; $c::someMethod(). After having obviously bored a few people there, I was finally replied that it wouldn't be supported which I found was mean at the time (I changed my mind, but still...). Derick even made fun of my request in his PHP Loop back 2002. Well with PHP 5.3, now it's time for REVENGE!

Now I am wondering if the following still works in PHP 5.3:
Class foo {
function bar() {
echo $this->param;
}
}

Class MyObject {
var $param;
function MyObject($param) {
$this->param = $param;
foo::bar();
}
}
$obj = new MyObject('out of this');

--> prints : "out of this"


It was pretty strange back then.
Comments (2)  Permalink

Tokyo Tyrant PHP network API

I have been working on a PHP class that communicates with a Tokyo Tyrant server through the network API. It is not finished, I need to add support for calling Lua extensions through the ext() function and I have to write more documentation. I also need to test it more.


This is MIT license, feel free to clone and test.

Comments (1)  Permalink

OMG PHP53!

Damn, I didn't really have the time to look at this version yet, but reading now the new features list, it looks like the most interesting PHP version ever.

I mean closures and lambda functions in PHP, I have been waiting for this for too long. Fileinfo, a very useful extension that I always had to compile is now bundled. Changes to the ternary operator ?:, hehe. A new MySQL driver which should eat less RAM ! ext/intl looks amazing too.

Well, this looks really great, I still have to test this (especially the anonymous functions) and see if it is as cool as it sounds.
Namespaces look weird with their antislash syntax tho... :/

Update : actually, given the long new features list, I start to wonder why they didn't call this version PHP6 ?
Comments (5)  Permalink

Bye bye PDFLib

I have been using PDFLib for over 4 years now on various projects. Of course, I had to buy the PDFLib license because most are commercial projects and we needed the PDI feature which allows you for example to use another PDF document as a template. So I bought the PDFLib 5 license, then the PDFLib 6 license update because if I remember correctly PDFLib 5 didn't support unicode or something like that. That's about 1000 euros each time.

Recently, we have upgraded our hosting plan from our hosting company and instead of a single CPU on the server, we now have two for the same price. It's a nice upgrade. Unfortunately, PDFLib didn't like the upgrade and now returns the following error when we generate a document with our serial number "Found 2 CPUs - license covers only 1".

Of course, I have contacted their sales department about the problem. They replied that I should either buy another license for PDFLib 6 for the second CPU, or eventually buy PDFLib 7 which doesn't have this per CPU limitation. Both solutions cost approximately the same price, more than 900 euros !

I don't feel like buying another license and I don't need PDFLib 7 "features". So, farewell PDFLib ! It was nice working with PDFLib but they obviously became too greedy.

I am going to investigate other toolkits. I know that most of them do not support features like PDI, but I can probably find another way around this issue. So far, I have found :

  • Haru : There is a brand new PECL extension for Haru written by Antony Dovgal which was released last week in version 1.0. Sounds interesting !
  • FPDF : These are mostly PHP classes. The author claims that it is not as fast as PDFLib but says it performs well. I have already tried this solution before and it was working very well but I was only producing PDF invoices for an e-commerce site. Building a full catalogue might be too much for it. The nice thing is its companion class FPDI which can also import existing PDF files and worked for me the last time I tried.
  • TCPDF : In the same vein as FPDF, these are a set of PHP classes for generating PDF documents. I need to have a look at it as well. It seems to work with FPDI too.
  • Panda : There is also a PECL extension for Panda, but I am not sure it is maintained and the project didn't release anything for a long time.
  • Cairo : Cairo has a backend for PDF rendering. Given its strengths in graphics, this can be interesting but I think it will be too limited in my case as I need to create documents with multiple pages. There is also a PECL Extension for Cairo (there are two actually, but the other one didn't make a release yet).

I now have to evaluate them and rewrite some code for our new server. But in the end, I won't have to deal with PDFLib and its licensing mess anymore, so that's for the better.

Update : based on your comments, here are other interesting libraries to deal with PDF within PHP, http://www.ros.co.nz/pdf/ (not updated and not unicode aware it seems), ezPdf (looks too much integrated in an over-engineered framework. I couldn't even figure out where to download the class...), Zend_Pdf (well documented but I am not sure it supports features like PDI for importing a PDF), dompdf (an HTML to PDF converter, it is not what I need).
Comments (17)  Permalink

On the move

There was recently an interesting post about scripting languages by Steve Yegge. What I particularly liked are the hints on other languages he gives and his invitation to try new languages.

I have been programming PHP since 1999 and felt a need to learn something new approximately when they launched Rails a few years ago. But instead of learning Rails, because I don't usually follow the hype, I decided to learn Python.

So, recently, I have been learning Python, then Ruby and now the Lua programming language. Out of these three languages, my favorite is Lua and it is where I spend most of my time now.

PHP blobThey are all excellent languages to learn and in many ways, they are better than PHP. As I said in a previous post, I now see PHP as a big blob which along the years have been developing in too many directions and is now facing a lot of problems because a lot of things were implemented incorrectly and were not carefully planned. It is not obvious at first, but when you start looking at other languages, you understand how some things could have been done and you realize how wrong they are in PHP. I am thinking of all the stuff you find in SPL, create_function(), call_user_function(), ::, $this->, parent::, instanceof, is_a(), the way static are handled, etc, etc. It's all a mess. And it starts to look in blog posts. From time to time, I read things about how nice it would be to have closures, traits, anonymous functions, weak references, duck typing in PHP and some hacks on how to imperfectly implement them.

And because PHP is not idiot proof, you will find a lot of people there with little knowledge about programming. Like this week's post of someone who says "function in_array() sucks because it is slow"... The more I know about programming and the less I find the PHP community interesting. It's like all the interesting people here are doing things secretly and don't take the time to share their experiences (unless they write books).

And the last things I have started to dislike is the way a company like Zend is taking over the language. I have also recently very much disliked Oracle buying InnoDB and Sun buying MySQL, although I was not surprised for MySQL given the road they had taken lately, which is actually a lot like the road PHP is taking with Zend at the moment. With rumors about Microsoft, Oracle, IBM buying Zend, I start to feel the fear. Because in the end, who decides what goes where in PHP core?

Here is a list of programming languages that deserve a look soon:

Comments (10)  Permalink

Recursive copy with pattern match on Unix

For a new online shop I am working on, I needed to copy all the products images from the old site to the new one. The challenge is that both sites don't run on the same server and a product can have multiple images which are stored in different subdirectories. Furthermore, I am not interested in copying thumbnails since those will be regenerated with better quality and probably different format.

In order to perform such a copy, recursive and using a filter, here is what I found on the net:

$ tar -cf - `find . -name "*_xl.jpg" -print` | ( cd ../dest tar xBf - )

This will recusively copy all my *_xl.jpg files into a ../dest directory, while also creating the subdirectories when needed. Perfect !

Comments (0)  Permalink

Lpdf on Mac osx

Here is a quick reminder on how I built Lpdf, the Lua bindings for pdflib, on my Intel mac.

  • 1. First, installed the PDFLib binaries
  • 2. Installed Lua from source
  • 3. Didn't bother about the Makefile in Lpdf
  • 4. Used the following sequence
export MACOSX_DEPLOYMENT_TARGET="10.3"
gcc -I/usr/local/include -Wall -O2 -fno-common -c
     -o lpdf.o lpdf.c
gcc -Wall -bundle -framework Carbon
     -undefined dynamic_lookup -o pdf.so lpdf.o 
     -L/usr/local/lib -lpdf

At first, I forgot the -framework Carbon flag which lead to dyld: Symbol not found: _FSPathMakeRef.

Comments (0)  Permalink

Stop stealing, innovate

Today I saw this proposal for the Zend Framework. I wouldn't be surprised if this proposal was accepted. Zend Framework seems to be unable to propose anything innovative to PHP developers. The examples provided on this page look like they are copy/pasted from code available in PEAR that already is 5 years old.

I think Zend as a software company has a real problem with innovation. Not surprisingly, PHP suffers the same problem. Most of (if not all) the new features are stolen from Java, C, C++, PERL, ... but nothing seems to be invented here anymore.

Of course, I think HTML_QuickForm2, the project we have been starting to work on will be a lot more interesting than these Zend_Framework proposals. It will be invented here and it will stay in PEAR. PEAR is where the innovation is. Zend_Framework is just, well..., a framework ?

Comments (11)  Permalink

My experience with Python

During the last 5 months, I have been learning Python. I read a few books about the language and subscribed to various mailing lists, RSS feeds and followed Open-Source projects.


Learning Python was easy and interesting. My experiences with programming languages so far have been mostly with PHP (since 1999), Objective-C, some C, Javascript and Actionscript for Flash. So I was at ease with Python and everything seemed well thought and designed.


Compared to PHP, Python is pretty. Even the syntax is prettier. The obligatory code indentation is in my opinion an excellent idea to make sure your code is readable and respects some coding standards. Compare this with the code you can find in PHP apps libraries where each script has its own way...


Python seems to have been thought from the start. On the other hand, features were added to PHP one after the other in order to "solve the web problem". So compared to Python, PHP looks like an ugly fat blob. It borrowed from C, Perl, Java, C++... In comparison, Python looks more like a nice girl in a pretty dress. But as Rasmus Lerdorf said, PHP was never designed to win a beauty contest.


I started learning Python mostly because I was getting bored with PHP. I write PHP code almost every day, 10 hours a day, so I wanted to try something new. I had to do it on my extra time since PHP is our language of choice at work. I picked Python instead of Ruby because I didn't want to follow the hype around Rails. I was also interested in projects like Python for Series60 from Nokia and pyObjC, a bridge between Python and the Cocoa framework.


As my work consists mainly in writting web application, my first attempts with Python were to see if I could also use it for the web. Well, the answer is not definitive but it's closer to no. Python is not ready for the web. The community is working hard on web frameworks but they go in every directions and none of them is well tested. And none of them is near PHP in terms of ease of use, features and deployement options.


Still, I really wanted so I picked up a simple web framework called Colubrid and tried to find a template engine that would fill my needs. In the past I have been using HTML_Template_Sigma and was after something as simple. Well, without success. There are a lot of template engines in Python but they are either too big and do easy thing the hard way, or they are too simple and don't support the basic stuff you would expect. So I decided to simply port HTML_Template_Sigma to Python.


In a way, I managed. My version supports everything that HTML_Template_Sigma supports. It took me 2,5 days approx. But the experience made me see how a language that tries to win the beauty contest is limited compared to its ugly brother. Here are some of the problems I met:

  • No isset(). If you use a variable that is not bound to an object, Python raises an exception, even if it's in a comparison clause. And you have no way prior to this exception to check whether the variable was bound. Some people suggest to catch the exception... This is like the chicken and egg problem.

  • Too many array types. PHP has only one type of array even if it can be used in different manners. Whether it is associative or not, the PHP arrays share the same set of funtions. In Python, you get dictionaries, tuples, lists, etc. And they don't have the same API. Arrays are probably the most useful way to store information in my code, with Python I always have to remember which kind of storage I used.

  • Values added to dictionaries are not stored in any specific order. Dictionaries are like associative arrays. Except that when you iterate them, the items you carefully added to them are listed in no specific order. This makes them totally useless and even dangerous. And there are no other datatypes provided by default to take care of your data in an ordered way. You have to write your own.

  • No easy one liners. I use a ? a : b; quite a bit in my code since it makes it shorter and easier to read (at least for me). You can't do something as simple in Python, you have to use convoluted ways.


There are a lot of other things in Python I felt were missing or wrong compared to PHP. The opposite is also true, but I mostly do web development and in this area PHP is way beyond. I agree that Python is a prettier language but that's not enough. Beauty is a subjective thing and to stay pretty you have to stay slim. I expect a language to provide me with the tools and the syntax to be as productive as possible, eventually with less code.


Actually, a lot of Python users seem to be in love with their language. They even invented a silly word to define and label other people's code : "pythonic" and "not pythonic". It means pretty. For example, interfaces, from Java or PHP5, are not pythonic. I actually got amused by the number of things that were not pythonic.


"Pythonic" is a geek term. In fact, I think Python is a language for geeks. The majority of Python users have no idea about marketing, business, promotion, press, corporate... Commercial terms are dirty. Python programmers like concepts and programming challenges. Python is their playground, their moment of fun, their hobby. There are actually a very little number of Python developers that seem to use the language for their living. Python is often used for prototyping and testing concepts.


I am not a geek and what I am really after is a tool to help me get more productive at work. Unfortunately, Python didn't fill my needs. I was happy to learn it and it showed me some interesting concepts implemented in interesting ways. Now I can read and write Python code that is maybe not "pythonic" but that does the job. Thanks to my initiation, I also discovered Mercurial, a very good RCS written in Python and switched to it from Subversion. I didn't loose my time, I simply had to try.


Now I am learning Ruby and enjoying it so far. It seems to fit the bill, along with Rails as a potential replacement to PHP. There is also an Objective-C/Cocoa bridge called RubyCocoa. Nothing for the Nokia Series 60, but this will force me to use my new Python skills so it's ok. In terms of beauty, I think Ruby won the contest over Python a long time ago. I will report about my experiences with Ruby later on.

Comments (9)  Permalink
Next1-10/27