PHP4 compatible namespaces

Get help with using the PHP Secure Communications Library.

Moderator: Nuxius

Forum rules
The purpose of this forum is to provide support for phpseclib, a pure PHP SSH / SFTP / RSA library.

Posts by new users are held in a moderation queue and are not publicly visible until the post is approved.

PHP4 compatible namespaces

Postby TerraFrost » Wed Jun 27, 2012 4:09 am

One thing that could be done to give phpseclib easy namespace support while retaining PHP4 compatibility would be to say that people wanting namespaces need to do require 'phpseclib.php' at the top of their file. namespace.php would then do this:

Code: Select all
<?php
function phpseclib_autoloader($class) {
    eval("namespace PhpSecLib; class Demo { function __toString() { return 'DDDD'; }}");
}

spl_autoload_register('\PhpSecLib\phpseclib_autoloader');

$a = new \PhpSecLib\Demo();
echo $a;
TerraFrost
Legendary Guard
 
Posts: 12218
Joined: Wed Dec 04, 2002 6:37 am

Re: PHP4 compatible namespaces

Postby TerraFrost » Wed Jul 04, 2012 4:19 pm

More playing around with PHP4 compatible namespaces...

Code: Select all
<?php
function phpseclib_autoloader($class) {
    eval("namespace PhpSecLib; class File_Demo { function __toString() { return 'DDDD'; }}");
    class_alias('\PhpSecLib\File_Demo', 'PhpSecLib\Demo');
}

spl_autoload_register('phpseclib_autoloader');

$a = new \PhpSecLib\Demo();
echo $a;

Also, streams could be used, instead of eval:

http://us3.php.net/manual/en/function.eval.php#100032

edit: another example:

http://stackoverflow.com/questions/1410 ... 9#14105559
TerraFrost
Legendary Guard
 
Posts: 12218
Joined: Wed Dec 04, 2002 6:37 am


Return to phpseclib support

Who is online

Users browsing this forum: No registered users and 1 guest

cron