Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
…lpa) This PR was squashed before being merged into the 3.2.x-dev branch (closes #239). Discussion ---------- Revert #237 and deprecate extending a protected closure Reverts #237 and throws a deprecation notice instead of an exception when attempting to extend a protected closure. As I said in silexphp/Silex#1538, I believe there are two ways to correctly handle the issue: 1. We throw an exception, considering that protected closures are parameters values and that extending them should be forbidden. 2. We allow users to extend anything. In that case, one should expect both these tests to work IMHO: ```php $pimple['foo'] = 'Hello'; $pimple['bar'] = $pimple->protect(function () { return 'Hello'; }); $pimple->extend('foo', function ($helloString) { return $helloString.' World'; }); $pimple->extend('bar', function ($helloClosure) { return $helloClosure().' World'; }); $this->assertSame('Hello World', $pimple['foo']); $this->assertSame('Hello World', $pimple['bar']); ``` Now, considering that Pimple invokes protected closures when the service is initialized, the current behavior forces you to do this instead (it basically ignores that the closure is protected and treats it as a regular, unprotected entry): ```php $pimple['bar'] = $pimple->protect(function () { return 'Hello'; }); $pimple->extend('bar', function ($helloString) { return $helloString.' World'; }); ``` That means both fixes would break BC, so I reverted #237 and added a deprecation notice instead. (PHP implementation is fixed, C is coming up) Commits ------- 9bcdb4d Revert #237 and deprecate extending a protected closure
- Loading branch information