In general, working with objects in PHP can be faster than working with arrays because objects are more predictable in terms of memory usage and performance. This is because objects have a fixed number of properties, while arrays can grow dynamically and potentially use more memory as a result.

To understand why this is the case, it's helpful to understand how PHP handles objects and arrays under the hood.

In PHP, objects are implemented as an instance of a class, which defines the properties and methods that the object can access. When an object is created, PHP allocates a fixed amount of memory to store the object's properties. This means that the memory usage of an object is predictable and does not change over time.

On the other hand, arrays are more dynamic and can grow or shrink as needed. When an element is added to an array, PHP will allocate additional memory to store the new element. If the array grows too large, PHP may need to reallocate memory to accommodate the new elements, which can be a slower process.

In terms of performance, working with objects can be faster than working with arrays because objects have a fixed number of properties, which means that PHP can access them more quickly. For example, when accessing an object property, PHP can simply look up the offset in memory where the property is stored, rather than having to search through an entire array to find the value.

In contrast, when working with arrays, PHP must search through the entire array to find the requested element, which can be slower. This is especially true for large arrays with many elements, as the search time grows linearly with the size of the array.

Here's a simple example to illustrate the difference in performance between working with objects and arrays:

php
// Define a class with a single property
class MyClass {
    public $property;
}

// Create an object and set the property value
$obj = new MyClass();
$obj->property = 'value';

// Create an array and set the element value
$arr = array();
$arr['property'] = 'value';

// Access the property or element
$obj_value = $obj->property;
$arr_value = $arr['property'];


In this example, accessing the $obj->property property is faster than accessing the $arr['property'] element because PHP can directly access the property in memory, rather than having to search through the array to find the value.

It's worth noting that the difference in performance between objects and arrays may not always be significant, especially for small data sets. In general, the performance difference between objects and arrays will depend on the specific use case and the size of the data being worked with.

In terms of the differences between PHP 7 and PHP 8, there have been several improvements to the performance of both objects and arrays in recent versions of PHP.

For example, in PHP 8, there have been significant improvements to the performance of objects, including the introduction of JIT (Just-In-Time) compilation and improvements to the object property cache. These changes have resulted in a significant boost in the performance of object-oriented code in PHP 8 compared to earlier versions.

There have also been improvements to the performance of arrays in PHP 8, including the introduction of a new array implementation called "packed arrays," which are optimized for small arrays with a fixed number of elements. Packed arrays can be significantly faster than traditional arrays in certain cases, especially when working with small data sets.

It's important to keep in mind that the performance of objects and arrays will depend on a variety of factors, including the size of the data being worked with, the specific operations being performed, and the version of PHP being used.

In general, objects may be faster than arrays when working with large data sets, especially if the data is accessed frequently, as the fixed memory usage of objects can make them more predictable in terms of performance.

On the other hand, arrays may be faster than objects in certain cases, such as when working with small data sets or when the data does not need to be accessed frequently. In these cases, the overhead of creating an object and defining its properties may outweigh the benefits of the fixed memory usage.

It's also worth noting that the performance differences between objects and arrays can vary depending on the specific operations being performed. For example, if you are performing a large number of insertions or deletions on an array, the performance may be slower than if you were simply accessing the values in the array.

In terms of the differences between PHP 7 and PHP 8, as mentioned earlier, there have been several improvements to the performance of both objects and arrays in recent versions of PHP. These improvements can vary depending on the specific use case and the size of the data being worked with, so it's always a good idea to benchmark your code to determine the best approach for your specific needs.

Here's an example of how you might benchmark the performance of objects and arrays in PHP:

php
// Define a class with a single property
class MyClass {
    public $property;
}

// Create an object and set the property value
$obj = new MyClass();
$obj->property = 'value';

// Create an array and set the element value
$arr = array();
$arr['property'] = 'value';

// Benchmark the performance of accessing the property or element
$start = microtime(true);

for ($i = 0; $i < 1000000; $i++) {
    $obj_value = $obj->property;
}

$end = microtime(true);
$obj_time = $end - $start;

$start = microtime(true);

for ($i = 0; $i < 1000000; $i++) {
    $arr_value = $arr['property'];
}

$end = microtime(true);
$arr_time = $end - $start;

echo "Object time: $obj_time\n";
echo "Array time: $arr_time\n";

This example creates an object and an array with a single property or element, and then benchmarks the performance of accessing the property or element. The code measures the time taken to access the property or element one million times and prints the results.

In this example, the performance of accessing the object property may be faster than accessing the array element, depending on a variety of factors such as the size of the data being worked with, the specific operations being performed, and the version of PHP being used.

To sum up, working with objects can be faster than working with arrays in PHP due to the fixed memory usage and more predictable performance of objects. However, the performance differences between objects and arrays can vary depending on the specific use case and the size of the data being worked with. In general, it's always a good idea to benchmark your code to determine the best approach for your specific needs. 

Another reason why you should always benchmark your code is that less computation time will automatically lead to less power consumption on the server. Clean (and optimized) code will lead to less energy used, thus can be seen as greener code, compared to less performant competitor code. The IT industry is only slowly adapting to the environmental issues humanity is facing, but cleaner code in the masses can make a slight change in energy consumption, too. Needless to say, that clean code will automatically be better in these aspects, clean code has much more benefits to offer than just that; in fact, the power consumption aspect is not even remotely the reason why you should improve your code. It has many (more important!) benefits besides that.