Hi Kevin,

Kevin Newman wrote:

> Thank you for the info.
> 
> I have some questions/suggestions (they may be silly - please feel
> welcome to tell me so, if they are):
> 
> You have solved the problem (grievance number 5) of file based scoping,
> by introducing a function that can only be used within __autoload (the
> autoload_import_class function). Is that function meant to be called
> from within the class file? If so, I'd like to offer an alternative,
> that would allow usage even outside of the __autoload function.
> 

The autoload_import_class function has nothing to do with solving the
file-based scoping problem. The way this was done internally was to have a
HashTable with the file names as key, and the values are each a HashTable
containing the import information.

The autoload_import_class function was created in order for full namespace
imports to be resolved from the __autoload function, regardless of which
file the __autoload function is in. For example, if we had two files,
test.php and autoload.php, and from test.php you have a statement "import
namespace my_ns" and you reference a class "my_class", then as soon as you
try to reference my_class, the __autoload function will be called (which is
in autoload.php). There needs to be a mechanism in which a namespace import
can be resolved from another file. The autoload_import_class does just
that. You pass it the class name and namespace name, and inside this
function, it adds this information to the import HashTable of the file that
triggered the __autoload call (in this case, test.php). After exiting
__autoload, the class is resolved and can be used by test.php.


> Namespaces are generally implemented in file based languages (like c,
> c++, c# etc.), so there isn't an issue with clearing out imported
> namespaces when a file ends - but since (let me know if this is an
> incorrect assumption) PHP is an inline based interpreter - it would make
> sense to have a way to remove namespaces after they have been imported.
> So the first suggestion is to add an unimport (export?) function that
> would do just that - remove imported classes (or functions/vars, etc.)
> from the current (or global?) scope.
> 

This is unnecessary, as there is a separate import HashTable for each file,
like I explained above.

I believe that what you were trying to accomplish with your pseudocode was
what is already being done internally, so I don't think it's relevant after
having explained the above (correct me if I'm wrong).


Regards,

Jessie

-- 
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to