You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Redeclaring protected properties on children creates a liskov violation #19406
After a discussion on the mailing list everyone seemed to agree it's a bug, and I believe fixing it wouldn't break any pre-existing code. Properties were invariant up to 8.4, and property hook variance is well defined.
PHP Version
PHP 8.4.10 (cli) (built: Jul 3 2025 12:35:27) (NTS)
Copyright (c) The PHP Group
Built by Debian
Zend Engine v4.4.10, Copyright (c) Zend Technologies
with Zend OPcache v8.4.10, Copyright (c), by Zend Technologies
with Xdebug v3.4.3, Copyright (c) 2002-2025, by Derick Rethans
I don't really know Liskov, but you're accessing a protected property from outside. The fact that C extends P has nothing to do with this. How this is a bug?
@alecpl The properties are related because of their shared parent property. Methods work the same way. You can call protected methods that are overridden in sibling classes.
@jnvsor Can you try PHP 8.4.12 RC1? It should be solved there by #19046. It should be released in ~2 weeks.
Activity
alecpl commentedon Aug 10, 2025
I don't really know Liskov, but you're accessing a protected property from outside. The fact that C extends P has nothing to do with this. How this is a bug?
alecpl commentedon Aug 10, 2025
OK, I saw the attached PR. I think I understand now. And I don't agree.
iluuu1994 commentedon Aug 15, 2025
@alecpl The properties are related because of their shared parent property. Methods work the same way. You can call protected methods that are overridden in sibling classes.
@jnvsor Can you try PHP 8.4.12 RC1? It should be solved there by #19046. It should be released in ~2 weeks.
jnvsor commentedon Aug 15, 2025
Thanks @iluuu1994 -- Tested with
docker run -it php:8.4.12RC1-zts-bookworm php -aand it doesn't throw an error any moreiluuu1994 commentedon Aug 15, 2025
@jnvsor Thanks for testing!