PHP Declaring constant in namespace

constants, namespaces, php

Solution

Ad 1. Yes you can. can be checked by running your example script; (but you may have to use `\paths\constant` or `use paths;` first)

Ad 2. subNs Can be checked by `echo __NAMESPACE__;`

Problem

I want to declare constants inside of a namespace. I want them not to be visible outside of it of course. Using define() won't work because it makes constants global regardless of the namespace it's executed in (if i understood well). So can i do : ``` namespace paths; const models = 'Models/'; const views = 'Views/'; const classes = 'Classes/'; ``` And somewhere else : ``` require_once(paths\models.'user.php'); // works require_once(models.'user.php'); // fails ``` Also if i do : ``` namespace ns; namespace subNs; ``` Am i in ns\subNs or in subNs ? PS: i know doing require_once('Models/user.php'); would be simpler, but that's just an example.

Original source