Edit report at https://bugs.php.net/bug.php?id=47472&edit=1

 ID:                 47472
 Comment by:         jeffreytgilbert at gmail dot com
 Reported by:        belliash at gmail dot com
 Summary:            Namespaces importing and usage
 Status:             Open
 Type:               Feature/Change Request
 Package:            Feature/Change Request
 Operating System:   Gentoo Linux
 PHP Version:        5.3.0beta1
 Block user comment: N
 Private report:     N

 New Comment:

I'm having the exact same issue. PHP 5.4.7. The Namespace is never imported and 
can only be used when referencing the full or partial namespace path. This 
isn't 
close enough to how the expected functionality would work. This makes partially 
useless because all existing code that didn't call namespaces directly with 
their full or partial path referencing classes/methods etc wont work. You can't 
simply wrap your classes in a namespace and have them encapsulated for easy 
import where appropriate. 

Errant code:
--------------------
<?php
namespace Minnow\Framework{
        class Startup{
                public static function launchApplication(){
                        echo 'Application launched';
                }
        }
}

namespace WebRoot{
        use Minnow\Framework;
        Startup::launchApplication();
}

Fatal error: Class 'WebRoot\Startup' not found in 
/Users/jeffreytgilbert/Desktop/Namespace-test-failure-use-namespace.php.php on 
line 12


Errant code: 
---------------------

<?php
namespace Minnow\Framework{
        class Startup{
                public static function launchApplication(){
                        echo 'Application launched';
                }
        }
}

namespace WebRoot{
        use Minnow\Framework;
        \Startup::launchApplication();
}


Fatal error: Class 'Startup' not found in 
/Users/jeffreytgilbert/Desktop/Namepsace-test-failure-root-namespace.php on 
line 
12



Errant code:

<?php
namespace Minnow\Framework{
        class Startup{
                public static function launchApplication(){
                        echo 'Application launched';
                }
        }
}

namespace WebRoot{
        use Minnow\Framework;
        Startup::launchApplication();
}



Fatal error: Class 'WebRoot\Startup' not found in 
/Users/jeffreytgilbert/Desktop/Namespace-test-default-namespace.php on line 12


=====================================
-- this is the part that chafes me
=====================================

<?php
namespace Minnow\Framework{
        class Startup{
                public static function launchApplication(){
                        echo 'Application launched';
                }
        }
}

namespace WebRoot{
        \Minnow\Framework\Startup::launchApplication();
}

Works fine, which is silly because then it makes the "use" arguments pointless 
because this still works, which it should, but doesnt work in the global or 
default scope. 

<?php
namespace Minnow\Framework{
        class Startup{
                public static function launchApplication(){
                        echo 'Application launched';
                }
        }
}

namespace WebRoot{
        use Minnow\Framework;
        \Minnow\Framework\Startup::launchApplication();
}


Previous Comments:
------------------------------------------------------------------------
[2009-07-02 20:46:32] qwerty763jd at php dot org

Huh, You released 5.3 and even does not check this bug report. You FAIL

------------------------------------------------------------------------
[2009-02-22 11:07:28] belliash at gmail dot com

Description:
------------
It is impossible to import namespace (to both global scope and to any other 
namespace).

It is only possible to alias namespaces...

Reproduce code:
---------------
/* utils_left.php */
<?php 
namespace Utils\Left;

function whichHand() 
{ 
    echo "I'm using my left hand!";
} 
?> 

/* utils_right.php */
<?php 
namespace Utils\Right; 

function whichHand() 
{ 
    echo "I'm using my right hand!";
} 
?> 

/* index.php */
<?php 
include('./utils_left.php'); 
include('./utils_right.php');

Utils\Left\whichHand();    // outputs "I'm using my left hand!"
Utils\Right\whichHand();  // outputs "I'm using my right hand!" 

use Utils\Left; 
whichHand();                 // outputs "I'm using my left hand!" 

use Utils\Right; 
whichHand();                 // outputs "I'm using my right hand!"
?>

Expected result:
----------------
I'm using my left hand!I'm using my right hand!I'm using my left hand!I'm using 
my right hand!

Actual result:
--------------
I'm using my left hand!I'm using my right hand!
Fatal error: Call to undefined function whichHand() in 
/home/Belliash/HtDocs/test/index.php on line 9


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



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

Reply via email to