Namcspaces and include()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]



I've been coding in PHP for almost two decades, but I've never used
namespaces in my code. Please verify or correct my understanding of how
namespaces work with include() or require().

In order for a namespace declared at the top of a file to actually be
of any use, the code file which defines the namespace originally must
be included somewhere in a file before the namespace declare. That is,

namespace \something
// some code which is used in other files

namespace \something
// the code which uses the namespaced code

include 'file1.php';
// include this before using the namespace code elsewhere 

In other words, the fact of declaring a namespace does not pull in that
code from elsewhere. You must do an include() or require() somewhere in
order to actually use the namespaced code.

I know, this sounds like a really dumb newbie question. Mea culpa.


Paul M. Foster
Personal Blog:
Company Site:
Software Projects:

[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux