In PHP4/5 there is an extension named "overload", it is enabled by default in PHP 4.3.0
and higher and also in PHP5. Below 4.3.0 it is usually enabled on most implementations.
Using this extension allows for property access and method calling of a class to be overloaded.
PHP's way of overloading is fairly diffrent in definition to overloading in more traditional OOP
language (c++, java), it works by defining a function within a class, __get, __set or __call. When
a property is accessed or a method is called within that class then the appropriate function gets
called, which provides the name of the propery/method that was used and whatever paramaters are
given. One must explicitly tell PHP to overload a class, as it is not done by default. this is done
with
When you do web projects for some time, an interesting pattern is likely to emerge. Tho every project has some specific features, many projects share some functionality. I had been programming customer-specific mini-web-CMS' for several months when copy-pasting and integrating all the same editable page, poll and scrolling test code for who knows how many times started to become a real pain.
I found an answer in isoliating pieces of functionality in libraries of functions, then stitching them together by including the library files. However after coupla projects I started to get problems with function names - they started to become real long and avoiding conflicts became a chore. Solution was to implement those pieces as classes. As the code was about showing some user inderface components, I called the classes "widgets". The result was very positive. Writing the widget code would now take maybe %30 more time but time gain during integration was tremendous.
Another unexpected advantage showed itself. I'm using Macromedia Dreamweaver MX for writing PHP code; I find it very useful, however it is unable to present PHP code in meaningful form. In "design" view, all the code between markup would be represented by a PHP icon. Being so it would now and again result in a real nightmare for the company designer and for me. Collecting all the relevant code under one widget class gave me a possibility of presenting user interface element as a separate item that could be manipulated easily in WYSIWYG mode.
Isn't writing new code great? Wouldn't the world be a better place if all were ever had to do is write software from scratch, not having to worry about methods of classes past? Unfortunately, we all know that this is not the case. In fact, estimates say that we spend around 80% of our programming time maintaining old code. So for this blog post will be trying to tackle that 80%, and I will see what I can do to make it less painful.
Joining mailing list will entitle you
to receive occasional emails informing you of news and
updates to the site and any special offers that may be
of interest to you.