note 119234 added to language.namespaces.faq

From: Date: Sun, 24 Apr 2016 09:02:05 +0000
Subject: note 119234 added to language.namespaces.faq
Groups: php.notes 
Request: Send a blank email to php-notes+get-205312@lists.php.net to get a copy of this message
Regarding the entry "Import names cannot conflict with classes defined in the same file". - I found that since PHP 7.0 this is no longer the case. In PHP 7.0 you can have a class with a name that matches an imported class (or namespace or both at the same time). <?php namespace ns1 { class ns1 { public static function write() { echo "ns1\\ns1::write()\n"; } } } namespace ns1\ns1 { class ns1c { public static function write() { echo "ns1\\ns1\\ns1c::write()\n"; } } } namespace ns2 { use ns1\ns1 as ns1; // both a class in ns1, and a namespace ns1\ns1 // the next class causes fatal error in php 5.6, not in 7.0 class ns1 { public static function write() { echo "ns2\\ns1::write()\n"; } } ns1::write(); // calls imported ns1\ns1::write() ns1\ns1c::write(); // calls imported ns1\ns1\ns1c::write() namespace\ns1::write(); // calls ns2\ns1::write() } ?> ---- Server IP: 72.52.91.14 Probable Submitter: 95.168.240.152 ---- Manual Page -- http://php.net/manual/en/language.namespaces.faq.php Edit -- https://master.php.net/note/edit/119234 Del: integrated -- https://master.php.net/note/delete/119234/integrated Del: useless -- https://master.php.net/note/delete/119234/useless Del: bad code -- https://master.php.net/note/delete/119234/bad+code Del: spam -- https://master.php.net/note/delete/119234/spam Del: non-english -- https://master.php.net/note/delete/119234/non-english Del: in docs -- https://master.php.net/note/delete/119234/in+docs Del: other reasons-- https://master.php.net/note/delete/119234 Reject -- https://master.php.net/note/reject/119234 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#205312) next »