3v4l.org

run code in 300+ PHP versions simultaneously
<?php @ini_set('display_errors', 'on'); class Configuration { public static function get($param) { return true; } } class Cart { public function getProducts() { return array(1); } } class Context { public $cart; public function __construct() { $this->cart = new Cart(); } public static function getContext() { return new Context(); } } if (Configuration::get('LEGAL_SHIPTAXMETH') && $cart = Context::getContext()->cart && $products = $cart->getProducts() && !empty($products)) { echo "OK"; } /** * The above code snippet fails, because I think the condition is parsed like this: * * Configuration::get('LEGAL_SHIPTAXMETH') && * $cart = (Context::getContext()->cart && $products = $cart->getProducts()) * && !empty($products) * * so $cart is undefined when getProducts is called * */

preferences:
50.14 ms | 402 KiB | 5 Q