ID:               44782
 Updated by:       [EMAIL PROTECTED]
 Reported By:      deleet at sapo dot pt
-Status:           Verified
+Status:           Bogus
 Bug Type:         Class/Object related
 Operating System: Fedora 6
 PHP Version:      5.3CVS-2008-04-19 (snap)
 New Comment:

This is not a bug, for this simple reason.  Let's take these two
scripts:

file1.php:
<?php
namespace One;
class Testing {

        function __construct() {
                
        }
        
        static function stuff() {
                echo 'I work!' . "<br />\n";
        }
}
$a = 'Testing';
?>

$file2.php:
<?php
namespace Two;
class Testing {

        function __construct() {
                
        }
        
        static function stuff() {
                echo 'I am sinister!' . "<br />\n";
        }
}
?>

file3.php:
<?php
namespace Two;
include 'file1.php';
include 'file2.php';
echo $a;
$a::stuff();
?>

What should the output be?  There is no deterministic way to do this. 
Dynamic class references always must be the fully qualified classname,
even within the namespace.

The same is true of doing:

$a = 'Testing';
$b = new $a;

and this is by design, as I understand it.  The easy way out is to use
$a = __NAMESPACE__ . '::Testing'; as this will allow renaming the
namespace without penalty.


Previous Comments:
------------------------------------------------------------------------

[2008-04-19 22:14:14] deleet at sapo dot pt

Very well, dynamic referencing it is then :)

Thank you for the quick reply, is it possible to get an ETA on the fix?

------------------------------------------------------------------------

[2008-04-19 21:43:26] [EMAIL PROTECTED]

This isn't late static bindings, but it's indeed a bug, probably
relying on the fact that Testing::$func(); would have been rewritten in
compile time.


------------------------------------------------------------------------

[2008-04-19 18:34:31] deleet at sapo dot pt

Description:
------------
Possible problem with the implementation of namespaces and late static
binding.

Reproduce code:
---------------
<?php

namespace Something;

class Testing {

        function __construct() {
                
        }
        
        static function stuff() {
                echo 'I work!' . "<br />\n";
        }
}

Testing::stuff();

$var = 'Testing'; $func = 'stuff';
// No effect: use Something;
$var::$func();
?>

Expected result:
----------------
Output:
------------------
I work!
I work!

Actual result:
--------------
Output:
------------------
I work!
Fatal error: Class 'Testing' not found in //file url// on line 20
------------------

PHP is not looking for the class inside the defined namespace when
using late static binding. It works if I use $var =
'Something::Testing'; but that's not indented behaviour. Also, using the
namespace seems to have no effect.


------------------------------------------------------------------------


-- 
Edit this bug report at http://bugs.php.net/?id=44782&edit=1

Reply via email to