3v4l.org

run code in 300+ PHP versions simultaneously
<?php $wp_version = '6.2.0'; // WP Core code. class Foo { public function __call( $name, $arguments ) { if ( 'new_method_A' === $name || 'new_method_B' === $name || 'new_method_C' === $name ) { return $this->$name( ...$arguments ); } $class = get_class( $this ); $trace = debug_backtrace(); $file = $trace[0]['file']; $line = $trace[0]['line']; trigger_error( "Call to undefined method $class::$name() in $file on line $line", E_USER_ERROR ); } private function new_method_A() { echo __FUNCTION__, ' called!', PHP_EOL; } private function new_method_B() { echo __FUNCTION__, ' called!', PHP_EOL; } public function new_method_C() { echo __FUNCTION__, ' called!', PHP_EOL; } } // Plugin code. $obj = new Foo(); if (method_exists($obj, 'new_method_A')) { $obj->new_method_A(); } else { // Do it some other way to support older WP versions. } if (method_exists('Foo', 'new_method_A')) { $obj->new_method_A(); } else { // Do it some other way to support older WP versions. } if (is_callable($obj, 'new_method_B')) { $obj->new_method_B(); // NOTE: doesn't work as method is private. } else { // Do it some other way to support older WP versions. } if (version_compare($wp_version, '6.2.0', '>=') === true) { $obj->new_method_C(); } else { // Do it some other way to support older WP versions. }
Output for git.master, git.master_jit, rfc.property-hooks
new_method_A called! new_method_A called! new_method_C called!

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:
187.28 ms | 405 KiB | 5 Q