in PHP by (10.3k points) recategorized by
0 like 0 dislike
28 views

According to the most programming languages scope rules, I can access variables that are defined outside of functions inside them, but in PHP for access to outside variable in function need bind (poin to variable) it with help key word "global". However, when I do same for outside constant, this doesn't work. Why doesn't this work? How to inside function get access to constant, what did be declare outside, in PHP?


php access global variable in function
php access global constant in function
php global constant in function

1 Answer

0 like 0 dislike
by (10.3k points)
It is not working because for getting access to constant don't need bind it via key word "global" in function in PHP. Key word "global" used only for outside variables. Access to outside constants in functions there have default. Just use outside constant in functions without key word "global".

Your answer

Try to answer the question as detailed as possible.
Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
Anti-spam verification:
To avoid this verification in future, please log in or register.