3v4l.org

run code in 500+ PHP versions simultaneously
<?php class Document { // Standard type public string $companyTitleStandard; // Union types public DocumentFieldCompanyTitle|string $companyTitleUnion; } $rp = new ReflectionProperty(Document::class, 'companyTitleUnion'); $unionTypes = array_map(function($type) { return $type->getName(); }, $rp->getType()->getTypes()); var_dump($unionTypes);
Output for 8.0.19, 8.1.2 - 8.1.34, 8.2.9 - 8.2.31, 8.3.0 - 8.3.31, 8.4.1 - 8.4.22, 8.5.0 - 8.5.8
array(2) { [0]=> string(25) "DocumentFieldCompanyTitle" [1]=> string(6) "string" }
Output for 7.4.22
Parse error: syntax error, unexpected '|', expecting variable (T_VARIABLE) in /in/SlbXX on line 9
Process exited with code 255.
Output for 7.3.33
Parse error: syntax error, unexpected 'string' (T_STRING), expecting function (T_FUNCTION) or const (T_CONST) in /in/SlbXX on line 6
Process exited with code 255.

preferences:
75.58 ms | 906 KiB | 4 Q