php - Declaring two namespaces in the one file -


as said in php reference

namespaces declared using namespace keyword. file containing namespace must declare namespace @ top of file before other code - 1 exception: declare keyword.

but further we've following code snippet in reference:

<?php namespace myproject;  const connect_ok = 1; class connection { /* ... */ } function connect() { /* ... */  }  namespace anotherproject; //this namespace declaration doesn't located @ top of file. it's unclear.  const connect_ok = 1; class connection { /* ... */ } function connect() { /* ... */  } ?> 

one declared @ top first 3 lines under myproject referes myproject namespace whereas other 3 under anotherproject refers anotherproject namespace. if @ least 1 namespace declared top, file correctly parsed (namespace switched dinamically)

just more clear, can that

<?php namespace myproject {  const connect_ok = 1; class connection { /* ... */ } function connect() { /* ... */  } }  namespace anotherproject {  const connect_ok = 1; class connection { /* ... */ } function connect() { /* ... */  } } ?> 

however not recommended declare 2 namespaces inside same php script


Comments

Popular posts from this blog

css - I want to align grid in center -

Contact Form PHP Email Script -

python - SWIG function not printing output -