What Are We Talking About Here? Real namespaces were only introduced in PHP 5.3, so it is quite normal to see what is called “poor man’s namespacing” in codebases that were started before PHP 5.3, or that try to still support PHP versions older than that. How Is It Being Used? When no real namespace is being used, all the functions that are defined within a PHP script execution lifecycle share a common global namespace. Each name within that global namespace can only be defined once. When a name is already taken, PHP will throw a fatal error when defining it again. This is referred to as a namespace collision (or naming collision). // ---[ File: as_silly_example_conflicting_syntax.php ]---// Constant risking a naming collision.const KEY = 'answer';// Global variable risking a naming collision.$data = [KEY => 42,];// Function declaration risking a naming collision.function get_data( $key ) {global $data;return $data[ $key ];}// ---[ File: use_as_silly_example_conflicting_syntax.php ]---// Output will (probably not) be "answer is 42".echo KEY . ' is ' . get_data( KEY ); When PHP did not yet have any namespaces, people (those who cared) generally used prefixes
Share This

We are using cookies on our website

Please confirm, if you accept our tracking cookies. You can also decline the tracking, so you can continue to visit our website without any data sent to third party services.