Skip Navigation
Expand
PHP 5.6.18 Upgrade - Technical Release Notes
Answer ID 8410   |   Last Review Date 09/18/2018

B2C Service August 2016:  PHP 5.6.18 Upgrade - Technical Release Notes

Environment:

PHP, Upgrades, August 2016 and newer
Audience:   Oracle B2C Service Site Administrators and Developers

Resolution:

Oracle B2C Service August 2016 will support PHP version 5.6.18.  Based upon the PHP community guidelines ('Migrating from 5.3 to 5.4', 'Migrating from 5.4 to 5.5' and 'Migrating from 5.5 to 5.6') as well as testing by the Service Cloud Team, the following issues will be remediated:

1. register_globals - The register_globals directive has been removed and is no longer available in versions of PHP 5.4.0+.
Example:
    if (authenticate_session($sessionid))
    {
        // display sensitive data
    }
If we are expecting $sessionid to be cookie data, this code will stop functioning correctly if register_globals is Off. The solution is to replace the uninitialized variable with the appropriate COOKIE predefined variable:
    if (authenticate_session($_COOKIE['sessionid']))
    {
        // display sensitive data
    }
It is also possible to use the $_REQUEST superglobal variable, but this is less secure than using the $_COOKIE variable in this case because $_REQUEST is an associative array that contains the contents of $_GET, $_POST, and $_COOKIE. Using $_REQUEST will leave the variable vulnerable to poisoning and should be avoided if possible.


2. call-time pass-by-reference - Call-time pass-by-reference was deprecated in PHP 5.3.0 and removed in PHP 5.4.0. Using call-time pass-by-reference will raise a fatal error in PHP 5.4.0+
Example:
    function increment_function(&$param)
    {
        $param++;
    }

    $x = 0;
    increment_function(&$x);

This example will raise a fatal error: Call-time pass-by-reference has been removed. The solution is simply removing the ampersand from the function call:
    function increment_function(&$param)
    {
        $param++;
    }

    $x = 0;
    increment_function($x);

There is another concern related to call-time pass-by-reference that is specific to Customer Portal. The functions called from the /config/hooks.php file must contain an ampersand in the function definition. Example
/config/hooks.php:
    $rnHooks['post_feedback_submit'][] = array(
        'class' => 'Test_model',
        'function' => 'hookTest',
        'filepath' => ''
    );

/models/custom/test_model.php:
    <?php
    class Test_model extends Model   {
        function __construct()
        {
            parent::__construct();
            //This model would be loaded by using $this->load->model('custom/Test_model');
        }

        function hookTest($data)
        {
            // do something
        }
    }

This example will not behave as intended if the ampersand is missing from the hookTest function definition. This is due to a change in /euf/src/application/rightnow/classes/RightNowHook.php:
    /**
     * Validates and runs the hook specified
     *
     * @return string -An error message if one is generated
     * @param $hookName string -The name of the hook to execute
     * @param $hookDetails Array -Array defining details about the hook to execute
     * @param $data Array -The data array to pass to the hook function handler
     */
    private static function runHook($hookName, $hookDetails, &$data)
    {
        $valid = self::validateHook($hookName, $hookDetails);
        if($valid !== true)
        {
            echo $valid;
            exit;
        }

        $modelPath = "custom/" . $hookDetails['filepath'] . "/" . $hookDetails['class'];
        $functionName = $hookDetails['function'];
        $modelName = $hookDetails['class'];
        self::$CI->load->model($modelPath);
        if(!method_exists(self::$CI->$modelName, $functionName))
        {
            printf(getMessage(HOOK_ERR_HOOK_PCT_S_FUNC_PCT_S_EX_MSG), $hookName, $functionName, $modelName);
            exit;
        }

-       return self::$CI->$modelName->$functionName(&$data);
+       return self::$CI->$modelName->$functionName($data);
    }
The solution is as simple as adding the ampersand to the function definition in the custom model if it is missing:
/models/custom/test_model.php:
    <?php
    class Test_model extends Model   {
        function __construct()
        {
            parent::__construct();
            //This model would be loaded by using $this->load->model('custom/Test_model');
        }

        function hookTest(&$data)
        {
            // do something
        }
    }

Please note that array() is a language construct used to represent literal arrays, and not a regular function. This should not be treated as a call-time pass-by-reference instance and therefore does not need to be changed for php 5.6.18 compliance. For example:

$$var1="1";
$arr1 = array(&$var1);


3. fgetcsv() - PHP has fixed fgetcsv() to no longer trim off leading whitespace.  If you require leading whitespace to be trimmed, you can use the ltrim() PHP function similar to the example below.

Example:
    PHP 5.3.2:        

        $fd = fopen('testcsv.csv', 'r');
        while ($a = fgetcsv($fd))
        {
            // import data
        }
    PHP 5.6.18 equivalent:          

        $fd = fopen('testcsv.csv', 'r');         
        while ($a = fgetcsvtrim($fd))         
        {             
            // import data         
        }          

        // remove whitespace to the left of csv values         
        function fgetcsvtrim($handle)          
        {             
             $results = array();             
             if ($values = fgetcsv($handle))             
             {                 
                  foreach ($values as $item)                 
                  {                     
                      $results[] = ltrim($item);                 
                  }             
             }              
             return $results;         
        }


4. _metadata - There have been changes to how metadata is accessed in Connect for PHP due to removal of being able to access static variables through an object instance in PHP:
Accessing static metadata property directly from an instantiated object is no longer allowed
"     $md = $incident->_metadata; // violates strict standards
"     $md = $incident->getMetadata(); // still works
"     $md = RNCPHP\Incident->_metadata; // still works

Accessing metadata to define a class now involves several steps.
"     Previously worked: $answer->AccessLevels= new $answer->_metadata->AccessLevels->type_name;
"     Doesn't work: $answer->AccessLevels = new RNCPHP\Answer->_metadata->AccessLevels->type_name;
"     Need: $class_name = $answer->getMetadata()->AccessLevels->type_name;
"     Followed by: $answer->AccessLevels = new $class_name;

 

5. date/time functions - Use of mktime() for defining a date/time now requires an explicit definition of the time zone. The default system time zone will not be used.  initConnectAPI() now calls date_default_timezone_set() using the time zone of the interface; please verify that initConnectAPI() is called before mktime().

Any  needed updates to PHP code will be completed before your site upgrades to Oracle B2C Service August 2016.  Changes will be made without impacting the functionality of the code.  Please avoid the introduction of any new PHP code that is not compatible with all PHP 5.6 rules and syntax.
Contact the PHP Upgrade Team on the Oracle Cloud Customer Connect Forum if you have any questions.

Available Languages for this Answer:

Notify Me
The page will refresh upon submission. Any pending input will be lost.