3v4l.org

run code in 300+ PHP versions simultaneously
<?php class ClosureStatementFactory implements StatementFactory { private $closure; function __construct(callable $closure) { $this->closure = $closure; } function create(\mysqli_stmt $statement, $queryString) { $function = $this->closure; $statementWrapper = $function($statement, $queryString); return $statementWrapper; } } function createTimerProxyXMySQLiStatementFactory(Timer $timer, Logger $logger) { //This is generated by the proxy builder which also generates the TimerProxyXMySQLiStatement class $closure = function ($statement, $queryString) use ($timer, logger) { $object = new TimerProxyXMySQLiStatement( $statement, $queryString, $logger, $timer ); return $object; }; return new ClosureStatementFactory($closure); } //This is how I tell what sort of StatementFactory the code should use. $provider->delegate(StatementFactory::class, 'createTimerProxyXMySQLiStatementFactory'); //And so the appropriate factory gets injected into: class DBConnection { //The database connection class needs to be able to make statement classes function __construct(StatementFactory $statementFactory) { $this->statementFactory = statementFactory; } function prepareQuery($query) { $mysqliStatement = $this->mysqli->prepareStatement($query); return $this->statementFactory->create($mysqliStatement, $queryString); } }
Output for 5.4.0 - 5.4.28
Parse error: syntax error, unexpected 'logger' (T_STRING), expecting '&' or variable (T_VARIABLE) in /in/7caND on line 24
Process exited with code 255.
Output for 5.3.0 - 5.3.28
Parse error: syntax error, unexpected T_STRING, expecting '&' or T_VARIABLE in /in/7caND on line 24
Process exited with code 255.

preferences:
183.47 ms | 1395 KiB | 65 Q