Warning: Division by zero in /var/customers/webs/stc/benchmark/index.php on line 256 Test: passing classes vs. arrays

PHP Benchmarks

Performance comparison of PHP code alternatives.

Test: passing classes vs. arrays

Is there any penalty (either way) in passing class objects vs. arrays? Theoretically, they are semantically equivalent.

Run Again Test Menu


Unfortunately, no history for this test is available.


The first test, "classes", was:

class Example
	var $x;

function example_class($x)
	$GLOBALS['dummy'] = $x->x;

$GLOBALS['test_object'] = new Example();
$GLOBALS['test_object']->x = 42;


The second test, "arrays", was:

function example_array($x)
	$GLOBALS['dummy'] = $x['x'];

$GLOBALS['test_array'] = array();
$GLOBALS['test_array']['x'] = 42;


Running: Linux (x86_64:1 GB) PHP (7.2.34-18+ubuntu16.04.1+deb.sury.org+1)