3v4l.org

run code in 300+ PHP versions simultaneously
<?php class InvalidArgumentType extends InvalidArgumentException { public function __construct(int $position, string $requiredType, $value) { $encoded = json_encode($value); if (strlen($encoded) > 10) { $encoded = sprintf('%s ... %s', substr($encoded, 0, 10), substr($encoded, -1)); } $inferredType = is_object($value) ? get_class($value) : gettype($value); parent::__construct(sprintf( 'Argument %d value %s should be %s but is %s.', $position, $encoded, $requiredType, $inferredType )); } } class Foo {} echo (new InvalidArgumentType(1, 'string', new Foo()))->getMessage().PHP_EOL; echo (new InvalidArgumentType(2, 'string', [1,2,3,4,5,6,7,8,9,10]))->getMessage().PHP_EOL; echo (new InvalidArgumentType(3, 'string', 123))->getMessage().PHP_EOL; echo (new InvalidArgumentType(2, 'string', null))->getMessage();
Output for git.master, git.master_jit, rfc.property-hooks
Argument 1 value {} should be string but is Foo. Argument 2 value [1,2,3,4,5 ... ] should be string but is array. Argument 3 value 123 should be string but is integer. Argument 2 value null should be string but is NULL.

This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.

Active branches

Archived branches

Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page


preferences:
147.5 ms | 406 KiB | 5 Q