# Class Constant Visibility BC Break

- Thread: https://externals.io/message/95357
- Original archive: https://news-web.php.net/php.internals/95357
- Started by Marc Bennewitz on 2016-08-21T20:57:30+00:00
- Messages: 2
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · RFCs at https://externals.io/rfc.md · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #95357 — Marc Bennewitz — 2016-08-21T20:57:30+00:00

URL: https://externals.io/message/95357#95357

Hi,


I encountered a problem of my library with the new class constant 
visibility functionality.

The problem is that I'm using ReflectionClass::getConstants() to detect 
class constants but I'm only interested in public constants.

Before class constants were public by definition but now it can be 
private and protected, too.

I know the new methods ReflectionClass::getReflectionConstant[s]() are 
available to detect exactly what I need and that's fine!

But of course using ReflectionClass::getConstants() no longer returns 
public class constants by default.


So for me this is a BC break but it wasn't listed in the RFC.

I don't know if it was discussed before but it could be avoided by 
adding an argument to ReflectionClass::getConstants() to filter by 
visibility which defaults to public.


Thoughts?


PS: I'm talking my library to emulate enumerations 
https://github.com/marc-mabe/php-enum/blob/master/src/Enum.php#L295-L327

but this BC break happens to all using ReflectionClass::getConstants() 
for public constants only e.g. accessing values later with `constant()`.


Cheers

Marc

---

## #95358 — Dan Ackroyd — 2016-08-21T22:24:53+00:00

URL: https://externals.io/message/95357#95358 · In reply to: #95357

Hi Marc


>
> So for me this is a BC break

So that we're clear about what we're discussing, please can you post
some example code that:

i) Works in PHP 7.0.x
ii) Won't work in PHP 7.1.x

cheers
Dan
