Running Enuuk on PHP 5.4

Discussions about the Enuuk Platform in general - both the GPL and Commercial versions
Post Reply
RWAP
Site Admin
Posts: 748
Joined: Fri Jan 08, 2010 2:23 am
Location: Stoke-on-Trent
Contact:

Running Enuuk on PHP 5.4

Post by RWAP » Thu Feb 14, 2013 4:25 pm

I have just started to look at running Ennuk on PHP 5.4 - unfortunately, some changes are required to the code:

In /index.php

Find:

Code: Select all

    $controller->processParameters($_SERVER,array_merge($_REQUEST,$_COOKIE)); //some PHP5.3 configs don't add Cookies to Request superglobal
Change this to:

Code: Select all

    $_REQUEST=array_merge($_REQUEST,$_COOKIE); //some PHP5.3 configs don't add Cookies to Request superglobal
    $controller->processParameters($_SERVER,$_REQUEST);
In class/Core/Controller.php
Find:

Code: Select all

        $url = array_shift(explode("?", $url)); //remove "?xx=xx&..."
Change this to:

Code: Select all

        $tmpUrl=explode("?", $url);
        $url = array_shift($tmpUrl); //remove "?xx=xx&..."
In class\Category.php
Find:

Code: Select all

    public function getOrderedListFromDB(MyPDO $DB, $restrictions='', $sortingType = self::ORDER_ALPHABETICALLY)
Change this to:

Code: Select all

    static public function getOrderedListFromDB(MyPDO $DB, $restrictions='', $sortingType = self::ORDER_ALPHABETICALLY)
In class\Offer.php
Find:

Code: Select all

    public function getInstance($type)
Change this to:

Code: Select all

    static public function getInstance($type)
In modules\class\PennyAuction.php
Find:

Code: Select all

    public function saveExtendedDataToBid(Bid &$bid, $parameters)
Change this (so that it is in line with the class\LotAuction.php file) to:

Code: Select all

    public function saveExtendedDataToBid(&$bid, $parameters)

RWAP
Site Admin
Posts: 748
Joined: Fri Jan 08, 2010 2:23 am
Location: Stoke-on-Trent
Contact:

Re: Running Enuuk on PHP 5.4

Post by RWAP » Fri Mar 08, 2013 1:04 am

In class\LotAuction.php

Find:

Code: Select all

    public function getQuantity(Bid $b)
Change this to:

Code: Select all

    static public function getQuantity(Bid $b)

RWAP
Site Admin
Posts: 748
Joined: Fri Jan 08, 2010 2:23 am
Location: Stoke-on-Trent
Contact:

Re: Running Enuuk on PHP 5.4

Post by RWAP » Sat Mar 23, 2013 4:01 pm

In:
modules\themes\default\offerDetailsPenny.php
modules\themes\default\offerDetailsReverse.php
themes\default\offerDetailsStandard.php
themes\default\offerDetailsLot.php
themes\default\offerDetailsFixed.php
themes\default\offerDetailsBasic.php

Find:

Code: Select all

                            <div><h4><a href="<?=$relativePath.$offerFile?>"><?=end(explode('/',$offerFile))?> [<?=round($fileSize,2)?>] <?=_('KB')?></a></h4></div>
Change this to:

Code: Select all

                            <div><h4><a href="<?=$relativePath.$offerFile?>"><? $cast=explode('/',$offerFile);echo end($cast)?> [<?=round($fileSize,2)?>] <?=_('KB')?></a></h4></div>

Then, in themes\default\offerForm.php

Find:

Code: Select all

                  <a href="<?=$relativePath.$fileOld?>"><?=end(explode('/',$fileOld))?> [<?=round($fileSize,2)?>] <?=_('KB')?></a>
Change this to:

Code: Select all

                 		<a href="<?=$relativePath.$fileOld?>"><? $cast=explode('/',$fileOld);echo end($cast)?> [<?=round($fileSize,2)?>] <?=_('KB')?></a>

RWAP
Site Admin
Posts: 748
Joined: Fri Jan 08, 2010 2:23 am
Location: Stoke-on-Trent
Contact:

Re: Running Enuuk on PHP 5.4

Post by RWAP » Tue Apr 16, 2013 9:39 am

Found another one:

In class\User.php

Find:

Code: Select all

    public function getUserIPList(MyPDO $DB, $userId)
    {
        return ($DB->query('select IP,date,blocked from '.self::USER_IP_TABLE.' where userId="'.$userId.'"')->fetchAll(PDO::FETCH_ASSOC));
    }
Change this to

Code: Select all

    static public function getUserIPList(MyPDO $DB, $userId)
    {
        return ($DB->query('select IP,date,blocked from '.self::USER_IP_TABLE.' where userId="'.$userId.'"')->fetchAll(PDO::FETCH_ASSOC));
    }

bamse
Posts: 220
Joined: Mon Feb 06, 2012 12:05 pm
Contact:

Re: Running Enuuk on PHP 5.4

Post by bamse » Sat Jul 13, 2013 10:17 am

I recently moved to PHP 5.4 and this post was useful to find some of the issues I had not encountered. So thanks for posting it.

Looking at the error log, some of the issues appear to me not really PHP 5.4 related, but rather due to sloppy programming in phpauction which PHP 5.4 likes perhaps less than earlier PHP versions. Regarding the "static" changes, they fix error messages like:
PHP Strict Standards: Non-static method Offer::getInstance() should not be called statically
when calling the method as Offer::getInstance() instead of something like $offer->getInstance()

So, my question is, should these things be fixed in general, also for people running older PHP versions?

RWAP
Site Admin
Posts: 748
Joined: Fri Jan 08, 2010 2:23 am
Location: Stoke-on-Trent
Contact:

Re: Running Enuuk on PHP 5.4

Post by RWAP » Sun Jul 14, 2013 8:42 am

Actually, PHP 5.4 contains a better pre-parser - the reason why the strict warnings appear is in case your code is supposed to be using a function connected to a class object and you have forgotten to use the object.

For example:

$offer=GetInstanceFromDB($this->db, $offerId)
$winner=$offer->getWinners($this->db)

would work (not sure the parameters are correct as I am not looking at the code)...

However, if you tried, by mistake:
$offer=GetInstanceFromDB($this->db, $offerId)
$winner=offer::getWinners($this->db)

In PHP 5.3 this would not cause an error or warning (!) and would appear to work, but not return anything useful!

In 5.4 it issues a strict warning...

Enuuk v3.2 does actually implement all of the changes needed for PHP 5.4 from what I have seen so far (I have not had chance to update my servers yet...)

So the answer is, that there is no harm in changing the code for earlier versions, and in fact to help prevent errors in your code, you should do so!

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest