Type Hinting Using Class Alias Results in Fatal Error
Permalink
I just discovered the cause of a very perplexing fatal error. The error occurred when I attempted to visit a page containing a GlobalArea. The error pointed to this line...
https://github.com/concrete5/concrete5-5.7.0/blob/master/web/concret...
...and basically said that the method is expecting an Area but got a GlobalArea instead. Obviously, this makes no sense because a GlobalArea is a subclass of Area. Anyway, it seems to be related to these issues...
https://bugs.php.net/bug.php?id=61422...
https://bugs.php.net/bug.php?id=39003...
The solution is to use the fully qualified class name either as part of the "use" import statement at the top or as the type hint itself.
I suspect this could be an issue anywhere else in the code base where a class alias is used for type hinting, so I thought I'd ask about the preferred method of fixing it. I'm guessing it would be best to use the fully qualified class name in the "use" statement at the top.
Or is there another way? I just want to be sure before submitting any pull requests.
Thanks,
-Steve
https://github.com/concrete5/concrete5-5.7.0/blob/master/web/concret...
...and basically said that the method is expecting an Area but got a GlobalArea instead. Obviously, this makes no sense because a GlobalArea is a subclass of Area. Anyway, it seems to be related to these issues...
https://bugs.php.net/bug.php?id=61422...
https://bugs.php.net/bug.php?id=39003...
The solution is to use the fully qualified class name either as part of the "use" import statement at the top or as the type hint itself.
I suspect this could be an issue anywhere else in the code base where a class alias is used for type hinting, so I thought I'd ask about the preferred method of fixing it. I'm guessing it would be best to use the fully qualified class name in the "use" statement at the top.
Or is there another way? I just want to be sure before submitting any pull requests.
Thanks,
-Steve
Check out these examples:
http://3v4l.org/akuXA vs http://3v4l.org/RU5eQ
Same code, different load order. Maybe this is something we can fix without doing away with aliases?