note 124210 added to language.namespaces.dynamic

From: Date: Thu, 19 Sep 2019 08:56:25 +0000
Subject: note 124210 added to language.namespaces.dynamic
Groups: php.notes 
Request: Send a blank email to php-notes+get-212249@lists.php.net to get a copy of this message
Important to know is that you need to use the *fully qualified name* in a dynamic class name. Here is an example that emphasizes the difference between a dynamic class name and a normal class name. <?php namespace namespacename\foo; class classname { function __construct() { echo 'bar'; } } $a = '\namespacename\foo\classname'; // Works, is fully qualified name $b = 'namespacename\foo\classname'; // Works, is treated as it was with a prefixed "\" $c = 'foo\classname'; // Will not work, it should be the fully qualified name // Use dynamic class name new $a; // bar new $b; // bar new $c; // [500]: / - Uncaught Error: Class 'foo\classname' not found in // Use normal class name new \namespacename\foo\classname; // bar new namespacename\foo\classname; // [500]: / - Uncaught Error: Class 'namespacename\foo\namespacename\foo\classname' not found new foo\classname; // [500]: / - Uncaught Error: Class 'namespacename\foo\foo\classname' not found ---- Server IP: 208.43.231.9 Probable Submitter: 185.85.3.168 (proxied: 37.120.131.142) ---- Manual Page -- http://php.net/manual/en/language.namespaces.dynamic.php Edit -- https://master.php.net/note/edit/124210 Del: integrated -- https://master.php.net/note/delete/124210/integrated Del: useless -- https://master.php.net/note/delete/124210/useless Del: bad code -- https://master.php.net/note/delete/124210/bad+code Del: spam -- https://master.php.net/note/delete/124210/spam Del: non-english -- https://master.php.net/note/delete/124210/non-english Del: in docs -- https://master.php.net/note/delete/124210/in+docs Del: other reasons-- https://master.php.net/note/delete/124210 Reject -- https://master.php.net/note/reject/124210 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#212249) next »