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
https://forums.phpfreaks.com/topic/297203-what-this-line-do/#findComment-1515741
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
https://forums.phpfreaks.com/topic/297203-what-this-line-do/#findComment-1515811
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
https://forums.phpfreaks.com/topic/297203-what-this-line-do/#findComment-1515818
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.