{"id":1780,"date":"2012-07-11T20:20:27","date_gmt":"2012-07-11T19:20:27","guid":{"rendered":"http:\/\/www.codingfriends.com\/?p=1780"},"modified":"2012-07-11T20:20:27","modified_gmt":"2012-07-11T19:20:27","slug":"php-use","status":"publish","type":"post","link":"https:\/\/www.codingfriends.com\/index.php\/2012\/07\/11\/php-use\/","title":{"rendered":"PHP &#8211; Use"},"content":{"rendered":"<p>From a follow on from my previous post about <a href=\"http:\/\/www.codingfriends.com\/index.php\/2012\/07\/10\/php-namespace\/\" title=\"namespace\">namespace<\/a>, when you want to use another name, shorter than the actual namespace of the namespace you are able to use &#8220;use&#8221;.  Probably best to show in code<\/p>\n<pre lang=\"php\">\r\ninclude \"codingfriends.php\";\r\n\r\nuse codingfriends as cf;\r\n\r\necho cf\\sayHello().\"<br\/>\";\r\n<\/pre>\n<p>the codingfriends.php file is <\/p>\n<pre lang=\"php\">\r\n<?php\r\nnamespace codingfriends;\r\n\r\nfunction sayHello()\r\n{\r\n    echo \"Say hello from codingfriends.\";    \r\n}\r\n\r\nfunction sayHelloFromSub()\r\n{\r\n    echo sub\\sayHello();\r\n}\r\n?>\r\n<\/pre>\n<p>so that the &#8220;use&#8221; will alter the namespace of codingfriends to cf instead so that you are able to call codingfriends as cf, so when <\/p>\n<pre lang=\"php\">\r\necho cf\\sayHello().\"<br\/>\";\r\n<\/pre>\n<p>is called it will call the codingfriends\\sayHello() function.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>php use<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[17],"tags":[391],"class_list":["post-1780","post","type-post","status-publish","format-standard","hentry","category-php","tag-use"],"_links":{"self":[{"href":"https:\/\/www.codingfriends.com\/index.php\/wp-json\/wp\/v2\/posts\/1780","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.codingfriends.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.codingfriends.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.codingfriends.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.codingfriends.com\/index.php\/wp-json\/wp\/v2\/comments?post=1780"}],"version-history":[{"count":1,"href":"https:\/\/www.codingfriends.com\/index.php\/wp-json\/wp\/v2\/posts\/1780\/revisions"}],"predecessor-version":[{"id":1781,"href":"https:\/\/www.codingfriends.com\/index.php\/wp-json\/wp\/v2\/posts\/1780\/revisions\/1781"}],"wp:attachment":[{"href":"https:\/\/www.codingfriends.com\/index.php\/wp-json\/wp\/v2\/media?parent=1780"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.codingfriends.com\/index.php\/wp-json\/wp\/v2\/categories?post=1780"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.codingfriends.com\/index.php\/wp-json\/wp\/v2\/tags?post=1780"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}