3v4l.org

run code in 300+ PHP versions simultaneously
<?php function guessObjectMethod($object, string $fieldName, string $prefix): ?string { if (\is_callable([$object, $method = $prefix.\str_replace(' ', '', \ucwords(\str_replace('_', ' ', $fieldName)))])) { return $method; } return null; } class Data { public function isValid() : bool { return true; } } $data = new Data(); var_dump(guessObjectMethod($data, 'valid', 'get')); var_dump(guessObjectMethod($data, 'isValid', 'get')); var_dump(guessObjectMethod($data, 'valid', 'is')); var_dump(guessObjectMethod($data, 'isValid', 'is')); // if my property is called `isValid` it won't work!
Output for git.master, git.master_jit, rfc.property-hooks
NULL NULL string(7) "isValid" 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:
127.79 ms | 405 KiB | 5 Q