class - PHP 5.5 Classname Resolution -


php 5.5 has implemented new feature new way retrieve classname through syntax ::class:

<?php  namespace testing;  class test{}  echo test::class; // testing\test; 

this works perfectly, alright? me , other friends wanted know why syntax returns classname when used alongside undeclared class. e.g.:

<?php  echo undeclaredclass::class; // undeclaredclass 

in several other cases error raised, not here. know, concrete basis if possible, why happen?

does have late static bindings or it's (temporary) limitation/bug of brand new feature?

finally official answer... relatively speaking. presented me identified requinix@php.net in bu report created today. exception how involved php development person is.

tl;dr

php doesn't need ot know definition of class fully-qualified name. required informations available in compile-time doesn't need load it.

director's cut

namespaces uses resolved in compile-time, i.e., when file compiled before execution. that's why there strict requirements in order use them.

because of of requirements, when php encounters class name can know fully-qualified name. thinking of filesystem namespace directory relative locations , use symlinks.

the class name either absolute ("\testing\test") or relative ("test"), , if relative normal name. [more context required]

namespace testing {     echo test::class; // \testing + test = \testing\test } 

or alias:

use testing\test aliasedtest; echo aliasedtest::class; // aliasedtest + use = \testing\test 

without of autoloading wouldn't work!

::class new tool expose information php has known.

this "extended answer" pretty same of received bug report. reason of apparent copy & paste because, originally, built answer stack overflow community


Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

jsf - How to ajax update an item in the footer of a PrimeFaces dataTable? -

django - CSRF verification failed. Request aborted. CSRF cookie not set -