Posts Tagged ‘PHP’

ZenCart 1.3.8 and PHP 5.2.11 Bug: problem login to admin area

October 15th, 2009

Yes, I do have some clients that still use ZenCart. In fact, some ZenCart stores are doing very well in terms of SEO and more importantly, sales. This morning, I ran a routine yum update command on one of my clients servers. To my surprise, after rebooting the admin was inaccessible. I’ll share with you the symptoms so you can identify it and the solution that worked for me.


The symptoms:

  1. Not able to login to Admin panel. More importantly, when you try to login it doesn’t show any error message.
  2. No admin is able to login, in other words, the problem is global.
  3. If you look in the php log files, you’ll find a similar line:
    PHP Fatal error:  Class ‘queryFactory’ not found in /var/www/html/includes/functions/sessions.php on line 54, referer:

What is happening:

While I am not sure exactly, this post in the ZenCart forums gave up a clue: it was something in PHP 5.2.11. Now, it may be a new bug in this new version or a bug that got resolved and as a result it broke something in the old ZenCart. Note that as of this writing, ZenCart 1.3.8 is about a year and nine months old. In internet time this is a significant amount of time.

The solution that

Once I had an assumption for what the problem is, I worked on reverting the PHP version to an older one. However, when I tried to revert using the Atomic repository – it did not work because while they do make old versions of php available, the php-common is not. I ended up removing the atomic repository and using CentOS repositories which provide PHP ver 5.1.6 something. Reinstalled, restarted apache, and vuala!

Now, only if the ZenCart team will get off their butts (or maybe get on their butts) and finish up what they call the next release of this eCommerce application!! What is the next version 1.4, 1.6, 2.0, 2.5? of ZenCart, well that is another discussion altogether.

ZenCart , ,

PHP SimpleXML Rules!

August 1st, 2009
Comments Off

Last week I was debugging an xml parsing utility in PHP. Debugging can be enjoyable when it goes well but in my case it just wasn’t happening. It felt like chewing mud. The issue was actually a bug within the libxml library which is a native PHP extension. Apparently it was a bug that was introduced in PHP version 5.2.6 and was addressed in version 5.2.8 or 5.2.9. The bug presented itself when using the xml_parser methods which are built into the PHP. It is the old way of parsing XML with PHP, the new way is using SimpleXML, SimpleXMLElement, or XMLReader objects.

Now, once I read over the documentation I realized how easy it is to use the new SimpleXML. Additionally, I reduced my XML related code size from 100+ lines to less than 20. Fun!

Here is a short example of how to use it, let’s say we have the following XML structure:

 <purpose>eCommerce LAMP Development</purpose>
 <application isInstalled="1">Apache</application>
 <application isInstalled="1">MySQL</application>
 <application isInstalled="1">PHP</application>

Now lets observe how to use the SimpleXML class:

//We'll assume that the above xml is represented as a string and located inside $xmlDoc
//Here we create the SimpleXML object named $xml from the xmlDoc shown above
$xml = simplexml_load_string($xmlDoc);

//Now we can loop through the nodes 
//Notice how the node translates to a property of the object)
foreach($xml->webservers->webserver as $webserver)
  //Here we can use $webserver as a sub-node
  echo "My Web Server Info:\n";
  echo "Hostname: " . $webserver->hostname . "\n";
  echo "Purpose: " . $webserver->purpose . "\n";
  echo "OS: ". $webserver->os . "\n";
  //Now we'll see how we can use the xml node attributes
  foreach($webserver->applications as $application)
    echo "Application: ". $application;
    echo ($application['isInstalled'] == 1 ? " is installed" : " is not installed");
    echo "\n";

That is it! easy right? I thought so. At least it is much easier than working directly with the old xml_parser methods which turns to be buggy in recent versions of PHP.

A word of caution: I found it is necessary to join the values of the SimpleXML object to a string, sometimes even to an empty string in case that I am sending it to a function. In other words, i had to use:


instead of simply:


and the reason is that otherwise PHP would pass a copy of the object instead of triggering the toString() method. By adding the empty string we force PHP to first convert it to string and then send it to the function or method.

Web Development ,

Method Overloading Workaround in PHP5

June 25th, 2009
Comments Off

This past week I had the need to use overloaded methods in PHP 5. Overloading a method in object oriented design is especially helpful when trying to achieve the same operation while the code needs to be triggered from different states of the application or even different locations of the application. In my case, I needed an overloaded constructor to a PHP class. Yes, constructors are also a bit different in PHP 5 but still workable.


To make a long story short, in PHP 5 there is no real way to overload a method like you can with Java. However, it seems like the developers of PHP 5 did have overloading methods in mind and allowed some form of it. It seems like allowing a real method overloads in PHP would be a special case of what the core developers actually allowed to do. The reason behind the current syntax is beyound me. I even tried to look for a PHP roadmap and see if proper method overloading will be introduced in the future but I could not find anything relevant.

A user with the name Noel has posted on DZone a little snippet of code that shows exactly how method overloading in PHP5 can be achieved.

Do you know of any intentions on including real method overloading in PHP6?

PHP/MySQL, Web Development , ,

Zend Studio 6.1: Wrong Way to Enhance a PHP IDE!

February 16th, 2009

In the past two weeks I have been doing some serious PHP development. Unlike .NET development where Microsoft’s Visual Studio is second to none, in PHP there was never a clear winner. So, I have decided to take the latest Zend Studio, version 6.1 on eclipse, for a spin.

As always, I give Zend, the company who created PHP a lot of respect. But with my usage of the Zend Studio IDE I have found more annoyances than features that helped me gain productivity. Here are some of the bad items I could not resist but rant about:

1. The entire solution now seems ‘gummy’. Where are the days when we can go through multiple PHP projects, and multiple PHP files in a few clicks and the IDE still feels ‘light’? Well, it doesn’t. In fact the more I use it the more this new IDE feels ‘yuck’.

2. My experience with the file/project manager on the left hand side was poor at best. If you have some scripts that update a file with fopen(), fwrite() – I had to force refresh on the parent folder of the updated file otherwise the IDE shows an error message when I try to open the updated file. What?

3. Auto complete is a little wierd. Ok, maybe a lot wierd. I really miss the auto complete that Zend Studio 5.5 used to have. While it is evident that the algorithms are trying their best to be smart, the whole user experience with the location of the auto complete windows, tabs vs enter keys to confirm the selection, and some inconsitencies in UI brings my frustration to uncharted levels. Dear Zend Develop team, can you please download and try Visual Studio and copy the ease of use? not hard to do.

4. Do I really need to create a new project, give it a name, choose a folder if all I want is a new PHP file? really? Do you ask your online users to fill out a 20 field form for a simple contact inquery? I DONT THINK SO.

5. Two files that I need my IDE to handle well: XML and SQL. All I ask for is to show me the text, dress it up with color, and handle nice any auto completion in a smart way. In this new versin of Zend Studio I was simply not able to open some XML files or the rigid editing of it made it impossible to work within the IDE, Notepad served nice in those cases. But this means failure to the IDE’s interface.

I do not know what made Zend decide on choosing a wrong turn with the latest version of Zend Studio (6.1). But it seems like the Zend team have decided to sacrifice a lot of functionality in order to cut on development efforts that the eclipse IDE supposedly provides. The only problem here is that eclipse’s features are weak and not good enough to be considered a good starting point for any PHP IDE who wishes to be claimed the best.

Time to try something new, the buzz seems to favor the latest PHP IDE by NuSphere: PHPEd.

PHP/MySQL, Web Development , , , ,

Looking Ahead: ZenCart ver 1.4

August 25th, 2008

The ZenCart developer team seems to be hard at work and preparing to deliver a new version of ZenCart: ver 1.4. The core developers posted a roadmap brief for version 1.4 back in September of 2007. Recently, additional entries have been posted in the forums describing in more detail the upcoming changes and signaling a new release is to be expected soon.

The currently described updates to ZenCart are done all around the DB, its architecture, and improving its performance. To summarise from the ZenCart forums:

New Database Driver Layer
Extremely light/flexible drivers make it easier to support other Database Types
Preliminary support for innodb and mysql transactions

Sql Caching system rewritten
Much easier to add new caching types
Preliminary Support for Memcache

Use of MPTT for category structure
Reduces number of queries needed to ‘describe’ the category structure
Improves user experience thru reduced page load times

Supporting Classes to reduce query load
Hugely reduces queries needed
Reuses queries using Cache to further improve performance

The roadmap for ZenCart ver 1.4 promises the following updates to the code (summarized):

  • Better usage of PHP 5.2 features. This also means 5.2 will be the new minimum requirement.
  • More Object Oriented code, less of the old osCommerce code.
  • Lots of DB improvements (some is described above, seems more is yet to come).
  • Category structure converted to MPTT format. MPTT stands for Modified Preorder Tree Traversal (explanation of MPTT).
  • Performance improvements for sites with lots of product attributes.
  • More function libraries converted to classes.
  • Duplicate components shared between admin and catalog.
  • Template system enhancements: less tables and more admin control.
  • Additional notifiers for the observer system.
  • Transaction support with InnoDB. Also mentioned as initial stage according to the recent posts of the updates that were done so far.
  • SwiftMailer instead of phpMailer.
  • Stock and SKU per product attribute.
  • Security enhancements.

Keep up the good work!

eCommerce, PHP/MySQL, Web Development, ZenCart , , , , , , , ,