In Symfony 3.4.17 there's a line in Symfony\Component\Cache\Adapter\AbstractAdapter.php
that triggers a PHpStorm warning:
$this->createCacheItem = \Closure::bind(
function ($key, $value, $isHit) use ($defaultLifetime) {
$item = new CacheItem();
$item->key = $key; //directly accessing protected property!
$item->value = $value;
$item->isHit = $isHit;
$item->defaultLifetime = $defaultLifetime;
return $item;
},
null,
CacheItem::class
);
The property $key, $value etc are protected properties of CacheItem();.
PHP should throw an exception when accessing protected proprties directly, I double checked it with this script:
<?php
class test {
protected $a = '';
}
$test= new test();
$test->a = 'b';
var_dump($test);
This throws 'PHP Fatal error: Uncaught Error: Cannot access protected property test::$a'.
Why is the Symfony code running without problems but is my script (correctly) failing?