Jump to content

What this line do?


colap

Recommended Posts

Almost.

 

There is a class somewhere named "Table" in the "Cake\ORM" namespace. Odds are it will be in a file Cake\ORM\Table.php (or .class.php or whatever) but that is not always true.

 

Normally to refer to that class in code you would have to write the full path, like

$table = new \Cake\ORM\Table();
With a use you can tell PHP that any mention of "Table" actually refers to Cake\ORM\Table, so you can write the shorter

$table = new Table();
Link to comment
Share on other sites

Almost.

 

There is a class somewhere named "Table" in the "Cake\ORM" namespace. Odds are it will be in a file Cake\ORM\Table.php (or .class.php or whatever) but that is not always true.

 

Normally to refer to that class in code you would have to write the full path, like

$table = new \Cake\ORM\Table();
With a use you can tell PHP that any mention of "Table" actually refers to Cake\ORM\Table, so you can write the shorter

$table = new Table();

arent Cake and ORM folders?

Link to comment
Share on other sites

They may be folders, but in this case you're dealing with namespaces, not folder structure. Assuming everything in Cake is using an autoloader, I would expect to find the namespaces correspond with the directory structure, but it certainly doesn't have to.

Link to comment
Share on other sites

 

Almost.

 

There is a class somewhere named "Table" in the "Cake\ORM" namespace. Odds are it will be in a file Cake\ORM\Table.php (or .class.php or whatever) but that is not always true.

 

Normally to refer to that class in code you would have to write the full path, like

$table = new \Cake\ORM\Table();
With a use you can tell PHP that any mention of "Table" actually refers to Cake\ORM\Table, so you can write the shorter

$table = new Table();

 

arent Cake and ORM folders?

 

They may be folders in this case, but namespaces do not have to have a matching directory structure.

 

In order to follow the PSR-0 standard, namespaces do have to have a matching directory structure. I'm not sure if CakePHP follows PSR-0 or not.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.