note 105394 added to language.namespaces.importing

From: Date: Sun, 14 Aug 2011 22:26:15 +0000
Subject: note 105394 added to language.namespaces.importing
Groups: php.notes 
Request: Send a blank email to php-notes+get-182483@lists.php.net to get a copy of this message
If you are testing your code at the CLI, note that namespace aliases do not work! (Before I go on, all the backslashes in this example are changed to percent signs because I cannot get sensible results to display in the posting preview otherwise. Please mentally translate all percent signs henceforth as backslashes.) Suppose you have a class you want to test in myclass.php: <?php namespace my%space; class myclass { // ... } ?> and you then go into the CLI to test it. You would like to think that this would work, as you type it line by line: require 'myclass.php'; use my%space%myclass; // should set 'myclass' as alias for 'my%space%myclass' $x = new myclass; // FATAL ERROR I believe that this is because aliases are only resolved at compile time, whereas the CLI simply evaluates statements; so use statements are ineffective in the CLI. If you put your test code into test.php: <?php require 'myclass.php'; use my%space%myclass; $x = new myclass; //... ?> it will work fine. I hope this reduces the number of prematurely bald people. ---- Server IP: 92.48.74.199 Probable Submitter: 86.174.131.206 ---- Manual Page -- http://www.php.net/manual/en/language.namespaces.importing.php Edit -- https://master.php.net/note/edit/105394 Del: integrated -- https://master.php.net/note/delete/105394/integrated Del: useless -- https://master.php.net/note/delete/105394/useless Del: bad code -- https://master.php.net/note/delete/105394/bad+code Del: spam -- https://master.php.net/note/delete/105394/spam Del: non-english -- https://master.php.net/note/delete/105394/non-english Del: in docs -- https://master.php.net/note/delete/105394/in+docs Del: other reasons-- https://master.php.net/note/delete/105394 Reject -- https://master.php.net/note/reject/105394 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#182483) next »