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

Result

Unfortunately, no history for this test is available.

Code

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;
*/

example_class($GLOBALS['test_object']);

The second test, "arrays", was:

/*
function example_array($x)
{
	$GLOBALS['dummy'] = $x['x'];
}

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

example_array($GLOBALS['test_array']);

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