Archivo de Julio de 2007

Optimizing for PHP 5; Object Visibility

Viernes, 20 de Julio de 2007

With our recent announcement of optimizing the osCommerce Online Merchant v3.0 release for PHP 5, I will begin blogging about the changes performed here for the v3.0 Alpha 5 and v3.0 Alpha 6 releases to serve as a guide for our community developers. This should help in understanding how the v3.0 framework is designed and how add-ons can take advantage of the optimized framework.

gophp5-100x33.pngOur decision to optimize the v3.0 framework for PHP 5 is based on the end of life support cycle for PHP 4 which ends at the end of this year. The announcement the PHP Group made regarding this coincides with the efforts of the GoPHP5 initiative whom which we are also supporting.

This allows us to concentrate on a PHP 5 optimized framework for future releases in the v3.x release series without the need to spend resources on PHP 4 compatibility past its end of life cycle.

The first PHP 5 optimized commits have already been performed in our development repository which reflects the classes and Object Oriented design of the framework. The new Object Model of PHP 5 allows us to tighten the design of the framework with the use of “object visibility”, and will be the first step in optimizing the framework for PHP 5.

Object visibility is in regard to defining class members and methods into three different visibility levels: public, protected, and private, which reflect how they can be accessed from outside the class, within the class, and within its inherited children.

The three levels function as:

public – this element can be accessed from inside and outside the class object
protected – this element can be accessed from inside the class object and its inherited children
private – this element can only be accessed from inside the class object

We’ll take a look at a shortened version of the session class to describe how each three visibility levels work.

class osC_Session {
protected $_id = null;
protected $_name = 'osCsid';

public function __construct($name = null) {
$this->setName($name);
$this->_setCookieParameters(SERVICE_SESSION_EXPIRATION_TIME);
}

public function getID() {
return $this->_id;
}

public function getName() {
return $this->_name;
}

public function setName($name) {
session_name($name);

$this->_name = session_name();
}

protected function _setCookieParameters($lifetime = 0, $path = null, $domain = null, $secure = false, $httponly = false) {
return session_set_cookie_params($lifetime, $path, $domain, $secure, $httponly);
}
}
?>

The class members $_id and $_name are both protected and allow only to be accessed from within the class and its inherited children. This disallows accessing these members from outside the class as shown in the following example:

$osC_Session = new osC_Session();

echo $osC_Session->_id; // not allowed
$osC_Session->_name = ‘test’; // not allowed
?>

To allow access to these members from outside the class they must be defined with the public visibility level. As we don’t allow this as part of our coding standards, get and set methods are defined in the class that allow public access to the class members, as shown in the following example:

$osC_Session = new osC_Session();

echo $osC_Session->getID(); // allowed
$osC_Session->setName(’test’); // allowed
?>

Accessing the getID() and setName() class methods from outside the class object is allowed as these have been defined with the public visibility level.

On the other hand, the _setCookieParameters() class method is defined with a protected visibility level and cannot be accessed from outside the class object. The _setCookieParameters() class method can therefore only be accessed from within the class and its inherited children, as is being done in the class constructor.

The session implementation in v3.0 (Alpha 5) has been impoved to allow modules to be loaded that define how the storage of the session data is accessed. An example session module is the database module that stores the session data in the database. Each session module is an extension to the osC_Session class and therefore inherits its class members and methods.

This allows the database session module, named osC_Session_database, to access the public and protected class members and methods from the main osC_Session class.

If there were class members and methods defined in the osC_Session class with the private visibility level, its inherited children such as the osC_Session_database class would not be allowed to access it.

The default behaviour in PHP 4 is to allow full public access to all class members and methods. By using the visibility levels PHP 5 provides, it is possible to disallow public access to class members and methods to keep certain functionality for internal use by the framework only.

Further information regarding object visibility levels can be read at the PHP Manual.

As each class is being updated in the framework, phpDocumentation is also being written to provide a developers API guide with the v3.0 release, that describes each class member and method. This documentation will be completed during v3.0 Alpha 5 and v3.0 Alpha 6.

osCommerce Online Merchant v3.0 and PHP 5

Jueves, 19 de Julio de 2007

The PHP Group recently announced that support for PHP 4 will be discontinued at the end of this year to focus on the production-ready PHP 5 and the upcoming PHP 6 releases.

The announcement from the PHP Group can be read here:

http://www.php.net/index.php#2007-07-13-1

This announcement impacts our current v3.0 development roadmap, our vision for the final v3.0 release, and our support policy for released versions, where we have decided to also drop support for PHP 4 in osCommerce Online Merchant v3.0 and to optimize it for PHP 5.

This gives us v3.0 Alpha 5 and v3.0 Alpha 6 to remove PHP 4 compatibility coding logic and to optimize the framework with the new features PHP 5 provides. As the current state of the v3.0 framework has already moved to an Object Oriented design, optimizing it for PHP 5 will be a simple task worth doing now to avoid jumping to v4.0 so soon which was planned to be PHP 5 optimized.

Optimizing osCommerce Online Merchant v3.0 for PHP 5 now allows us to further improve and strengthen the framework and to pass the high quality level of coding to community developers to base their add-ons on. The performance of the framework will improve by removing the PHP 4 compatibility layer and by taking advantage of the new features PHP 5 provides such as SimpleXML, DateTime, Iterators, and new core functions. The design and security of the Object Oriented framework will also improve by utilizing the new features of the PHP 5 Object Model.

Our support policy for the v3.x release series is to publish a release with new features every 6 months and to support each published release for 2 years. Removing the PHP 4 compatibility layer now for the v3.0 release allows us to focus only on PHP 5 without the need to spend resources on PHP 4 compatibility past its end of life cycle.

Many hosting providers have been supporting PHP 5 in recent years together with PHP 4 where this change will not impact many users. The number of providers supporting PHP 5 will increase by the end of the year to match the end of life support for PHP 4.

The osCommerce Online Merchant v2.x release series will continue to be compatible with PHP 3, PHP 4, and PHP 5 from v2.2 onwards.

We are highly motivated about this change in focus and look forward in making osCommerce Online Merchant v3.0 an even better release.

This announcement can be discussed on the community support forums at:

http://forums.oscommerce.com/index.php?showtopic=270025

osCommerce Online Merchant v2.2 RC1 Released

Miércoles, 4 de Julio de 2007

We are proud to announce an advancement of the osCommerce 2.2 release cycle with a new release titled osCommerce Online Merchant v2.2 Release Candidate 1. This is primarily a bug fix release for the 2.2 series and will be the last release made before the 2.2 release series is finalized. We are currently in the process of certifying the payment modules included in this release which will be the only change for the final osCommerce Online Merchant v2.2 release planned in the coming weeks.

No major features have been introduced with this release candidate as our development efforts are focused on our upcoming 3.0 release, but does include the following changes:

* Over 25 bug fixes and improvements
* register_globals compatibility for PHP 4.3+ servers
* Visa PCI conformance of accepting credit card information on the checkout confirmation page
* Public titles for payment modules so the name of the payment service provider is not used as a payment method
* Maximum number of product quantities that can be added to the shopping cart (by default 99)
* New login routine for the Administration Tool
* New summary modules to display on the Administration Tool index page
* New web-based installation routine (backported from 3.0)

This release candidate also introduces a new name for the solution titled “osCommerce Online Merchant” that strengthens our presence and marketing efforts for our upcoming releases.

osCommerce Online Merchant v2.2 Release Candidate 1 can be downloaded here:

http://www.oscommerce.com/redirect.php/go,41 (hosted at Sunsite.dk)

An upgrade guide for existing osCommerce 2.2 Milestone 2 060817 installations can be found here:

http://www.oscommerce.com/ext/osc22rc1_upgrade.html.zip

This announcement can be discussed on the community support forums at:

http://forums.oscommerce.com/index.php?showtopic=268335

We wish you the best of fun with this release and look forward to your feedback!