2.2 MS2 And 2.2 MS3 IncompatibilitiesLast Update: 7th April, 2005
Article ID: 7



Introduction

The original Workboard entries for reaching a final 2.2 release of osCommerce had introduced a layer of incompatibilities through two impending milestone releases.

The Workboard for the remaining milestone releases has been updated to concentrate the incompatibilities on just one milestone release instead of the originally set two milestone releases.

This allows the API to be frozen once Milestone 3 is finalized, with Milestone 4 acting as a testing release before a finalized 2.2 package is made available.

This proposal documents the incompatibilities and changes Milestone 3 brings, to better aid developers and contributors at updating their work.

Usage of Classes

Milestone 3 introduces new classes that optimizes and strengthens the codebase, and provides a consistent means of interaction.

Just as the custom functions use a standard tep_* (soon osc_*) naming scheme, classes will now follow a similar scheme of osC_ClassName.

Using a standard naming scheme helps developers quickly identify the content of variable names, for example, is $customer the instance I am looking for, or is it $osC_Customer?

All session related data are now accessed with the new osC_Session class - starting, registering, unregistering, retrieving, and destroying session related data is done through the $osC_Session instance.

By using the consistent means the osC_Session class provides, developers can now identify if the variable they are accessing is in the session scope or the local scope, for example, $customer may be used at the local scope, whereas $osC_Session->value('customer') retrieves the variable from the session scope.

PHP Compatibility

With the introduction of the classes and strengthened focus on the "secure, stable, and efficient" goal, PHP 3 compatibility has been dropped and the focus now is to take advantage of what the latest PHP 4 version offers, while remaining compatible to PHP 4.0.x.

The primary change here is the codebase being register_globals compatible, allow_call_time_pass_reference compatible (for PHP 4.2 and PHP 5), and to produce no PHP messages when error_reporting is set to E_ALL (which shows all warning and error messages).

Being compatible to all PHP 4 versions, in all types of PHP configuration environments, puts the responsibility on developers to follow the osCommerce coding standards in order for their development work to integrate and work properly with the codebase, and to keep the goal of being "secure, stable, and efficient" true.

Super Global Variables

PHP 4.1 introduces the concept of super global variables with $_GET, $_POST, $_SESSION, $_COOKIE, etc, which contains the data specific to each scope, and does not need to be set as a global variable within functions. [As was required with PHP 4.0.x with $HTTP_GET_VARS, $HTTP_POST_VARS, etc]

As the super global variables exists from PHP 4.1 onwards, references to these variables are set for PHP 4.0.x servers for compatibility reasons. These references are however not "super global" and need to be set as globals within functions.

PHP 4.1 onwards has the possibility of corrupting data in the specified scope when super global variables are declared as globals within functions. To bypass this possibility, a check for the PHP version is made within functions that need to use data within the super global variable scope.

For example:


01: <?php
02
:   function osc_some_function() {
03:     if (PHP_VERSION < 4.1) {
04:       global $_GET, $_POST;
05:     }
06:
07:     /* function logic here */
08:   }
09: ?>



Line 3 checks if the PHP version in use is below 4.1 (4.0.x), and if true, declares the referenced $_GET and $_POST variables as global on line 4.

The referenced super global varaiables are set in includes/functions/compatibility.php.

Variable Changes

Here is a list of variable changes between Milestone 2 and Milestone 3:

[array] $HTTP_GET_VARS -> $_GET
[array] $HTTP_POST_VARS -> $_POST
[array] $HTTP_COOKIE_VARS -> $_COOKIE

Example:

$HTTP_GET_VARS['products_id'] -> $_GET['products_id']


[boolean] $session_started -> $osC_Session->is_started

[string] $SESSION_SSL_ID -> $osC_Session->value('SESSION_SSL_ID')
[string] $SESSION_USER_AGENT -> $osC_Session->value('SESSION_USER_AGENT')
[string] $SESSION_IP_ADDRESS -> $osC_Session->value('SESSION_IP_ADDRESS')

[object] $cart -> $osC_Session->value('cart')

The $cart instance is referenced in includes/application_top.php as PHP does not support dereferencing objects (ie, $osC_Session->value('cart')->reset()).


01: <?php
02
: // create an instance of the shopping cart
03:   if ($osC_Session->exists('cart')) {
04:     $cart =& $osC_Session->value('cart');
05:   } else {
06:     $cart = new shoppingCart;
07:     $osC_Session->set('cart', $cart);
08:   }
09: ?>



This means that accessing this objects data is not done through $osC_Session->value('cart') but $cart, which is the referenced variable on line 4.


[string] $language -> $osC_Session->value('language')
[integer] $languages_id -> $osC_Session->value('languages_id')

[string] $currency -> $osC_Session->value('currency')

[object] $navigation -> $osC_Session->value('navigation')

Similar to the $cart variable, the $navigation instance is referenced in includes/application_top.php as it is an object in the session scope.


[integer] $customer_id -> $osC_Customer->id

[integer] $cartID -> $osC_Session->value('cartID')

[integer] $sendto -> $osC_Session->value('sendto')
[integer] $billto -> $osC_Session->value('billto')

[string] $comments -> $osC_Session->value('comments')

[string] $payment -> $osC_Session->value('payment')
[string] $shipping -> $osC_Session->value('shipping')

[object] $currencies -> $osC_Currencies

Function Changes

Here is a list of function changes between Milestone 2 and Milestone 3:

tep_session_start() -> $osC_Session->start()
tep_session_register() -> $osC_Session->set()
tep_session_is_registered() -> $osC_Session->exists()
tep_session_unregister() -> $osC_Session->remove()
tep_session_id() -> $osC_Session->setID(), $osC_Session->id
tep_session_name() -> $osC_Session->setName(), $osC_Session->name
tep_session_close() -> $osC_Session->close()
tep_session_destroy() -> $osC_Session->destroy()
tep_session_save_path() -> $osC_Session->setSavePath(), $osC_Session->save_path
tep_session_recreate() -> $osC_Session->recreate()

tep_get_tax_rate() -> $osC_Tax->getTaxRate()
tep_get_tax_description() -> $osC_Tax->getTaxDescription()

tep_currency_exists() -> $osC_Currencies->exists()

Class Changes

Here is a list of class changes between Milestone 2 and Milestone 3:

$currencies -> $osC_Currencies

$currencies->display_price() -> $osC_Currencies->displayPrice()
(now passes the product tax class id as a (second) parameter instead of the product tax rate value (saves queries when DISPLAY_PRICES_WITH_TAX is disabled))

$currencies->is_set()
(removed due to $osC_Currencies->exists())

$currencies->get_decimal_places() -> $osC_Currencies->decimalPlaces()

$currencies->get_value() -> $osC_Currencies->value()

$osC_Currencies->format()
(removed $calculate_currency_value (second) parameter due to redundancy - if the number should not be calculated with the currency rate, a value of '1' should be passed as the currency rate)

 

 

Trademark Policy | Copyright Policy | Sitemap

Copyright © 2000-2005 osCommerce. All rights reserved.