Skip to content

Tag: php

PHP | define() vs. const

In PHP, you can declare constants in two ways: With define keyword Using const keyword What are the main differences between those two? When and why should you use one and when use the other? Answer As of PHP 5.3 there are two ways to define constants: Either using the const keyword or using the define() func…

Finding the PHP File (at run time) where a Class was Defined

Is there any reflection/introspection/magic in PHP that will let you find the PHP file where a particular class (or function) was defined? In other words, I have the name of a PHP class, or an instantiated object. I want to pass this to something (function, Reflection class, etc.) that would return the file s…

Is it possible to access outer local variable in PHP?

Is it possible to access outer local varialbe in a PHP sub-function? In below code, I want to access variable $l in inner function bar. Declaring $l as global $l in bar doesn’t work. Answer You could probably use a Closure, to do just that… Edit : took some time to remember the syntax, but here&#8…