-
In PHP 5 a new concept was introduced, type hinting. This feature allows validation of a parameter for a certain type.
This validation type is very popular in object orientated languages and I believe it represents a plus for the PHP object model and even more for his dynamic nature it self.
In PHP 5.1 validation for the array data type was added.
Let’s take a small example:
1class a { } 2 3class b { } 4 5function testa (a $a) { 6 echo "Bla bla\n"; 7} 8 9testa(new a()); 10 11testa(new b());
The result is:
1Bla bla 2 3Fatal error: Argument 1 passed to testa() must be an instance of a, called in ...
Cool, ha?
The type in which we can validate can be a class, an abstract class or even an interface which is inherited by other classes, like:
1interface inherited { } 2 3class a implements inherited { } 4 5class b implements inherited { } 6 7function testa (inherited $a) { 8 echo "Bla bla\n"; 9} 10 11testa(new a()); 12 13testa(new b());
And the above example will not raise any errors.
Unfortunately there is no way to validate primary (or scalar) data types. When PHP 5.3 was being released there have been some discussions on the subject, but it seems that it was too late, and the patch did not make it to the final version.
Yesterday, while I was doing my morning reading at a cup of coffee, what do I see on Ilia Alshanetsky blog: Scalar Type Hints are Here! Well, is a little exaggerated, there are not exactly here but there really close. Basically there are in the SVN trunk and will be available in the next stable version!
Of course that even in the current version of type hinting is not exactly mandatory to use it in PHP, is more of an issue of fine tune.
Basically we could already validate to a certain primary data type, but still:
1function testint($var) { 2 if(!is_int($var)) { 3 trigger_error("Type must be Integer", E_USER_ERROR); 4 } 5 ....... 6}
is not exactly as elegant as:
1function testint(int $var) { 2 ...... 3}
-
Packt Publishing has published a new book on the RAD PHP framework CodeIgniter version 1.7. The book CodeIgniter 1.7 Professional Development written by Adam Griffiths, has the slogan “become CodeIgniter experts with professional tools, techniques and extended libraries”.
Just from the slogan you can see a slightly different tone then the book CodeIgniter 1.7 from Packt Publishing, which in my opinion has the purpose of showing what the CodeIgniter framework can do.
This book has the purpose of showing how can you develop professional applications, or at least until proven otherwise, stay tuned to find out!
An argument for the slogan is the target audience like is defined in the “Who this book is written for” section, which contains the phrase:
Basic knowledge of CodeIgniter will be helpful.
A dangerous phrase in my opinion, because it can scare off a beginner, even though in the book it looks like all the steps are described starting from server installation.
If from the first book I was expecting a general presentation of the framework, now I’m curios to see if the examples are more ample and more concrete.
From the sample chapter it looks like there is a lot of code. As long as it is logical I thing it’s a good thing, a lot of times is easier to understand code, which you will after all write and you can take as an example, then theory.
But more about this book after I’ll get to read it.
To be continued…
-
PHP for desktop, is it worth it?
PHP is described on Wikipedia as:
PHP: Hypertext Preprocessor is a widely used, general-purpose scripting language that was originally designed for web development to produce dynamic web pages.
Taking this into consideration, apps divide in 3 category: web, command line and desktop.
For the Web, PHP is the most popular open-source (and not only) programming language.
PHP CLI
PHP CLI (Command Line Interface) I find it very interesting, even though is not used at it’s full potential. A lot of developers prefer shell scripting or Perl with no real reason. I’ve been playing around with this tool and I liked the result.
Important frameworks like: Zend, Symfony or Cake PHP are using PHP CLI to generate projects, models, CRUD or other features that can be easily used with a command line.
In the Windows environment the command line is not exactly popular, but in Linux is almost imperative. After all what’s the point of using shell scripting when you can use a powerful language with a lot of features like PHP?
But CLI is not limited just to the command line, it is usually used for cronjobs, pipes, socket-servers etc.
PHP-GTK
When it comes to PHP and desktop usually people thing about PHP-GTK. What do I thing about the project? Is not dead, like it says on the official website, but is not exactly alive. The reason? Gtk is not exactly simple. If you come from the Linux environment probably is not that difficult, but if you usually work on the web is not exactly html… Nevertheless there is a community that keep this project alive.
Nevertheless, it allows developers to build desktop apps in PHP, compatible with a wide variety of operating systems.
But there is an issue, the resulting apps are not exactly compiled code, they must run using a PHP virtual machine. Here is the issue, how do you distribute the app? If you have a small app of only few lines of code, to distribute it with a virtual machine is a little complicated… Also the code is visible, of course there are methods to solve this issue, but there aren’t exactly simple.
This is probabily the most popular PHP platform for desktop, if you can say that about this environment.
The documentation is pretty big, it was taken from the C++ version. Is not as well polished like the PHP manual for instance, but I believe is sufficient.
Winbinder
Compared to PHP-GTK it has an disadvantage, it only works on MS Widows operating system. The advantage is that it has a much simpler API. If I had to choose a PHP platform for desktop, probably I would go for Winbinder. Unfortunately is in the same state, is not dead but is not exactly alive. It also have the support of a community, but without any particular special results.
The issue with the compiled code is found here also, and even more the issue with platform distribution is just as bad. I firmly believe that if you want to develop an app using this platform, to make it work on your computer is the easiest part, to make it work on someone else’s computer is the real issue…
The documentation is pretty small, because of the API. But simplicity is good when it comes to programming, that means you can easily build pretty interesting apps.
Compilers
There a few, and the majority of them have some issue because they use old PHP versions of even old GTK. I’ve spend many hours on Google trying to find some reals solution but with no success.
Most popular compilers:
- Bambalam – works well with CLI and Winbinder. But it has a great disadvantage: it’s only compatible with PHP 4.4.4, and I believe that says it all. Anyway I believe it was the most interesting solution, unfortunately to old (the last version was released in 2006).
- PriadoBlender – works well with PHP-GTK and CLI, but is not very stable. The last (beta) version was released in 2007, and since then nothing new was ever heard from it. Probably if that version would be updated it would help a lot the PHP-GTK project.
Conclusion
When it comes to Web, everything is great!
PHP as a command line tool is ever more popular and more tools appear each day!
In the desktop environment is a “the living dead” sensation… This projects are not dead but there not exactly alive. Of course there are other solution for PHP on desktop which I did not mention, but there are in about the same state. Probably a new approach would help, something more attractive for web developers and those passionate about this language.
-
After my second little project, I’m back with my opinion on Adobe AIR!
Working with Adobe AIR I had a revelation, in 2004 John Battelle and Tim O’Reilly presented the concept “Web as Platform”. These days, using the Web as a platform we can develop desktop applications. Basically we’ve left an environment to come back to it with a new perspective.
If the first time I had only 3 days at my disposal, this time I wasn’t constrained. During this time I had the opportunity to discover some of the features, like NativeMenu and the support for SQLite.
I believe that SQLite has the purpose of compensating for the storing possibility that are not available on this platform, like cookies. Of course, SQLite is using a database, and the storing is way superior to the traditional Web.
But way choose Adobe AIR compared to other platforms like Java or C#? Because it is simple! I don’t believe that Adobe AIR was intended to be a tool for developing large applications, even though only time will tell if that’s possible. This is a great tool for small to medium scale apps, which can bring something extra to the Web. For instance in my app I had an alert system, I thought what I would like next to what I already have on the Web. With this alerts I don’t have to check all the time what’s new. Just as well I believe features like chats can be implemented or similarly features, after all if it can be done on the Web, it can be done here.
What Adobe AIR has is a very interesting distribution system, basically the platform is distributed with Adobe Acrobat Reader, thing that can make it available even on your computer without even knowing.
What Adobe AIR does not have, and I thing it would be useful, is a system for accessing COM objects for instance, possibility to access different database systems different then SQLite, which is quite simple.
Another feature that I would like is the possibility to access Adobe Flesh features from JavaScript. I know, I should use Flash if there are Flash features, but I prefer JavaScript as a platform. Probably the reason this features are not available in JavaScript is because this language has the HTML 5 features, like: Canvas and Audio, which somehow compensate with Flash features that are not available in JavaScript by default.
Adobe AIR 2 which is in beta version for the moment, will probably solve some of the need to access the system resources.
In my opinion, Adobe AIR is the platform on which a Web developer can develop desktop apps with ease!
-
CodeIgniter is an open-source PHP framework build for RAD.
The book CodeIgniter 1.7 from PacktPublishing, written by Jose Argudo Blanco and David Upton is trying to build an overall image of of the CodeIgniter framework, as an addintion to the user guide.The book is not a reference, and that becomes obvious with every chapter, each time a new feature of the CodeIgniter framework is introduced the user is directed to the corresponding page of the module in the user guide or wiki. Even more, suggestions are made for alternative modules that can achieve a similar task in a different way.
Authors say that only minimal knowledge of PHP is necessary to read this book, a promise that is hard to keep in my opinion, usually books that target novice to medium skill readers are saying something like that. To my surprise they ware right, the reader only needs PHP4 knowledge. And when it comes to OOP not even PHP5 features are required, just the PHP4 object model. In this book even the copping objects by reference is described! Of course copping objects by reference is no longer a relevant issue with PHP5, but taking this in to consideration that is an PHP4 framework it was a good idea to mention and explain it. It seems like there are still PHP4 server on the Internet… that is just sad…
Reading the book flashbacks came to my mind with pieces of code written directly in PHP and the hell of debugging them, trying to understand other peoples code… what times… horribly of course. The reasoning behind this concepts of re usability in a framework is just great: “Possibly you like typing regex. Some people like lying on a bed of nails…”. When a developer, especially a beginner, is reading something like this it makes him understand that you don’t have to reinvent the wheel each time, but just use solutions already developed by others.
Comparing between different available solutions I believe is the most funny part of a book like this. Is difficult or even impossible to compare for instance Zend Framework or even CakePHP with CodeIgniter. After all almost all frameworks say the same thing, just download and start working. Personally when I need to use a module from Zend Framework I just load the autoloader and get to work. The comparison shows CodeIgniter as a winner for most users, as expected, the reasoning behind that claim is pretty honest. Afterall is a small framework and does not have complex features like autogenerating CRUD. I remember a Java book where the author was representing the fact that C++ is faster then Java as a disadvantage, of course was just silly.
I sometimes had the impression that the terms were wrongly defined. The authors are using “small” mistakes in terms to explain what’s actually happening in the background. When you are working with MVC frameworks some of the notions are simple and obvious, but for a developer that’s not familiar with that terms there are quite hard to comprehend.
And to continue with the mistakes in the book, I’ve found a few. Quite a difficult moment when you start learning something new. Fortunately there are quite obvious because they result in errors, and if you read chapter after chapter you’ll know what the issue is and how to fix it.
Examples are pretty consistent and well documented. When a new concept or module is introduced it is fully explained in detail.
The resulting apps are not very complex, for instance at the end of the book there isn’t a full complex app like a CMS, rather modules and the way there are combined is explained. The user will have to decide in the end how will his app look and feel. For instance in chapter 13 pagination and ordering is explained. When pagination is used everything is OK, but when ordering is introduced the pagination begin to slip. It took me about 5-10 minutes to fix the issue, but it would have been nice for the authors to fix the issue themselves.
Overall is a good book, especially for users that have no prior knowledge of CodeIgniter, is just like is presented by the authors, a book for developers that want more productivity in there work or just what to see what other tools are out there. The book does not present full solutions like a CMS or a shopping cart, but rather what this framework has to offer.
An advanced developer can understand from this book the structure of the CodeIgniter framework, possibly to compare it to other popular frameworks, without loosing time with complex and irrelevant examples.