Function __isset and model lazy loading with different behaviour in PHP version 7.0.6 or newer

The behaviour of the PHP function __isset was changed with PHP version 7.0.6, see PHP7 Changelog.

OXID eShop makes use of this function __isset for lazy loading, and because of these changes lazy loading might behave unexpectedly in OXID eShop.

Let’s say there’s a lazy loading object of the type \OxidEsales\Eshop\Application\Model\Article, and you want to use oxtitle in your module view but it isn’t loaded yet:

$article = oxNew(\OxidEsales\Eshop\Application\Model\Article::class);
$article->load('oxidOfArticle');
isset($article->oxtitle->value);

PHP 7.0.5 or older would return true: first __get function on $artcicle->oxtitle will be called, oxtitle will be loaded then it checks if a value is set.

When running PHP 7.0.6 or newer, it returns false: first __isset function will be called on $article->oxtitle and returns false, because oxtitle isn’t loaded yet.

All relevant places were fixed in OXID eShop version 6.0.1 when introducing isPropertyLoaded(). Please make sure you avoid running into issues by loading the property first in your modules or in projects where you still run older Shop versions:

$title = $article->oxtitle;

and then check the value:

//will return true on PHP versions both older and newer than 7.0.6
isset($title->value);

 



Start the discussion at OXID forums