[php-src] Issue #7746: mysqli_sql_exception->getSqlState()
| From: | KapitanOczywisty | Date: | Thu, 23 Dec 2021 13:52:57 +0000 |
| Subject: | [php-src] Issue #7746: mysqli_sql_exception->getSqlState() | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-238546@lists.php.net to get a copy of this message | ||
Issue: https://github.com/php/php-src/issues/7746
Comment Author: KapitanOczywisty
Besides Reflection you can also access any
private or protected property
with closure binding. This is useful for over-protected classes.
```php
$sqlstate = (function () {return $this->sqlstate; })->call($class);
// this also works with arrow functions
$sqlstate = (fn () => $this->sqlstate)->call($class);
```
If you need to access private field of base class, use Closure::bindTo,
but you can't use an internal class as the second argument.
```php
class Bar {
private $foo = "Secret";
}
class Baz extends Bar {}
$class = new Baz();
$foo = (fn() => $this->foo)->bindTo($class, Bar::class)();
```