3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php class VarStorage { protected $_property; public function setProperty($value) { $this->_property = $value; } public function getProperty() { return $this->_property; } } function mem_print($message, $before, $after) { $difference = ($after - $before) / 1000000; echo sprintf($message, sprintf('%.2fM', $difference)); echo "\n"; } echo "Testing class in a PHP script\n\n"; // Create massive variable $mBeforeA = memory_get_usage(); $a1 = str_repeat('a', 3000000); $mAfterA = memory_get_usage(); mem_print('Creating $a1: %s', $mBeforeA, $mAfterA); // Refcount increases $a2 = str_repeat('a', 3000000); $mBeforeB = memory_get_usage(); $b = $a2; $mAfterB = memory_get_usage(); mem_print('$b = $a2: %s', $mBeforeB, $mAfterB); // Separation $mBeforeSeparation = memory_get_usage(); $b .= ''; $mAfterSeparation = memory_get_usage(); mem_print('$b .= '': %s', $mBeforeSeparation, $mAfterSeparation); // Setting to a class property $a4 = str_repeat('a', 3000000); $class = new VarStorage; $mBeforeStorageSet = memory_get_usage(); $class->setProperty($a4); $mAfterStorageSet = memory_get_usage(); mem_print('$class->setProperty($a4): %s', $mBeforeStorageSet, $mAfterStorageSet); // Getting from a class property $mBeforeStorageGet = memory_get_usage(); $result = $class->getProperty(); $mAfterStorageGet = memory_get_usage(); mem_print('$result = $class->getProperty(): %s', $mBeforeStorageGet, $mAfterStorageGet); $mBeforeSeparationFromStorage = memory_get_usage(); $result .= ''; $mAfterSeparationFromStorage = memory_get_usage(); mem_print('$result .= \'\': %s', $mBeforeSeparationFromStorage, $mAfterSeparationFromStorage);
Output for 5.4.0 - 5.4.17
Parse error: syntax error, unexpected '': %s'' (T_CONSTANT_ENCAPSED_STRING) in /in/Q4s6g on line 42
Process exited with code 255.
Output for 5.3.0 - 5.3.27
Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING in /in/Q4s6g on line 42
Process exited with code 255.