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

android - Get AccessToken using signpost OAuth without opening a browser (Two legged Oauth) -

org.mockito.exceptions.misusing.InvalidUseOfMatchersException: mockito -

google shop client API returns 400 bad request error while adding an item -