3v4l.org

run code in 300+ PHP versions simultaneously
<?php declare(strict_types=1); namespace Crell\ObjectAnalyzer; class ObjectAnalyzer { public function analyze(string|object $class, string $attribute): object { $subject = match (is_string($class)) { true => new \ReflectionClass($class), false => new \ReflectionObject($class), }; $classDef = $this->getAttribute($subject, $attribute) ?? new $attribute; if ($classDef instanceof ReflectionPopulatable) { $classDef->fromReflection($subject); } if ($classDef instanceof Fieldable) { $fields = $this->getPropertyDefinitions($subject, $classDef::propertyAttribute()); $classDef->setFields($fields); } return $classDef; } /** * @return Field[] */ protected function getPropertyDefinitions(\ReflectionObject|\ReflectionClass $subject, string $propertyAttribute): array { // The list of filters here is going to grow, so wants pipes. $rProperties = $subject->getProperties(); // Wants PFA $properties = array_map(fn(\ReflectionProperty $p) => $this->getPropertyDefinition($p, $propertyAttribute), $rProperties); //$fields = array_filter($fields, fn(Field $f): bool => !$f->skip); return $properties; } // Wants a generic return. protected function getPropertyDefinition(\ReflectionProperty $property, string $propertyAttribute): object { $propDef = $this->getAttribute($property, $propertyAttribute) ?? new $propertyAttribute(); if ($propDef instanceof ReflectionPopulatable) { $propDef->fromReflection($property); } return $propDef; } protected function getAttribute(\Reflector $target, string $name): ?object { return $this->getAttributes($target, $name)[0] ?? null; } protected function getAttributes(\Reflector $target, string $name): array { return array_map(fn(\ReflectionAttribute $attrib) => $attrib->newInstance(), $target->getAttributes($name, \ReflectionAttribute::IS_INSTANCEOF)); } }

Here you find the average performance (time & memory) of each version. A grayed out version indicates it didn't complete successfully (based on exit-code).

VersionSystem time (s)User time (s)Memory (MiB)
8.3.70.0040.01518.18
8.3.60.0150.00618.18
8.3.50.0140.00317.86
8.3.40.0130.00618.54
8.3.30.0090.00618.59
8.3.20.0080.00024.18
8.3.10.0050.00324.66
8.3.00.0060.00326.16
8.2.190.0070.00716.63
8.2.180.0090.00625.92
8.2.170.0070.00718.58
8.2.160.0140.00422.96
8.2.150.0050.00325.66
8.2.140.0030.00524.66
8.2.130.0070.00026.16
8.2.120.0050.00326.16
8.2.110.0080.00020.54
8.2.100.0060.00318.85
8.1.280.0040.01125.92
8.1.270.0090.00023.99
8.1.260.0040.00426.35
8.1.250.0040.00428.09
8.1.240.0100.00018.50
8.1.230.0030.00622.20
8.0.80.0060.01316.75

preferences:
43.75 ms | 401 KiB | 5 Q