ASPN ActiveState Programmer Network
ActiveState
/ Home / Perl / PHP / Python / Tcl / XSLT /
/ Safari / My ASPN /
Cookbooks | Documentation | Mailing Lists | Modules | News Feeds | Products | User Groups


Recent Messages
List Archives
About the List
List Leaders
Subscription Options

View Subscriptions
Help

View by Topic
ActiveState
.NET Framework
Open Source
Perl
PHP
Python
Tcl
Web Services
XML & XSLT

View by Category
Database
General
SOAP
System Administration
Tools
User Interfaces
Web Programming
XML Programming


MyASPN >> Mail Archive >> php-dev
php-dev
RE: [PHP-DEV] Simple Namespace Proposal
by Dmitry Stogov other posts by this author
Jul 23 2007 10:12AM messages near this date
Re: [PHP-DEV] Simple Namespace Proposal | RE: [PHP-DEV] Simple Namespace Proposal
Hi,

At first "import Zend::DB" is equivalent of "import Zend:DB as DB";

<?php
require 'Zend/Db/Connection.php';
import Zend::DB;

After these statement you can use any classes and functions from Zend::DB
namespace qualifying them by prefix "DB::".

$x = DB::Connection();

Thanks. Dmitry.

>  -----Original Message-----
>  From: Arpad Ray [mailto:arpad@[...].com] 
>  Sent: Monday, July 23, 2007 8:37 PM
>  To: dmitry@[...].com
>  Cc: 'Hans Lellelid'; 'PHP internals'
>  Subject: RE: [PHP-DEV] Simple Namespace Proposal
>  
>  
>  
>  Hi Dmitry,
>  
>  What made me think it's supported is that both the proposal 
>  and tests include namespace imports. Quoting from the proposal:
>  
>  > Namespace or class name can be imported:
>  > 
>  > <?php
>  > require 'Zend/Db/Connection.php';
>  > import Zend::DB;
>  
>  And ns_002.phpt:
>  
>  > import test::ns1;
>  
>  So if not importing everything in the namespace, what exactly 
>  are these statements supposed to do?
>  
>  I'm also curious why the direct importing of classes would be 
>  the only exception (why not functions too?), is this an 
>  unavoidable inconsistency?
>  
>  Regards,
>  
>  Arpad
>  
>  
>  
>  On 7/23/2007, "Dmitry Stogov" <dmitry@[...].com> wrote:
>  
>  >Hi Arpad,
>  >
>  >You have to always use namespace name as prefix for acesing 
>  namespace 
>  >entities. (The only exception is direct import of calss).
>  >So expectatins in your tests are wrong.
>  >
>  >Thanks. Dmitry.
>  >
>  >> -----Original Message-----
>  >> From: Arpad Ray [mailto:arpad@[...].com]
>  >> Sent: Sunday, July 15, 2007 7:32 PM
>  >> To: Dmitry Stogov
>  >> Cc: 'Hans Lellelid'; 'PHP internals'
>  >> Subject: Re: [PHP-DEV] Simple Namespace Proposal
>  >>
>  >>
>  >> Dmitry Stogov wrote:
>  >> > The patch is already committed to the HEAD.
>  >> >
>  >> > Dmitry.
>  >> >
>  >> There seem to be some problems with importing across 
>  files. The tests 
>  >> currently in CVS are all in single files so it's not immediately 
>  >> obvious. When a namespace is declared in one file and imported in 
>  >> another, classes must be addressed absolutely either in 
>  the import or 
>  >> when used, and functions must be addressed absolutely when used, 
>  >> irrespective of imports.
>  >>
>  >> I've attached some phpt files to test this, but here's a simple
>  >> illustration:
>  >>
>  >> foo.php:
>  >> <?php
>  >> namespace foo;
>  >> function foobar() { }
>  >> class Foobaz { }
>  >> ?>
>  >>
>  >> bar.php:
>  >> <?php
>  >> import foo;
>  >> foobar(); // error
>  >> new Foobaz; // error
>  >> foo::foobar(); // ok
>  >> new foo::Foobaz; // ok
>  >>
>  >> import foo::foobar;
>  >> import foo::Foobaz;
>  >> foobar(); // error
>  >> new Foobaz; // ok
>  >>
>  >> import foo::foobar as foobar2;
>  >> foobar2(); // error
>  >> ?>
>  >>
>  >>
>  >> Arpad
>  >>
>  >
>  

-- 
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php
Thread:
Dmitry Stogov
Derick Rethans
Dmitry Stogov
Dmitry Stogov
dz
David Coallier
Guilherme Blanco
Stanislav Malyshev
Dmitry Stogov
Markus Fischer
Stanislav Malyshev
Stanislav Malyshev
Stanislav Malyshev
Giedrius D
Stanislav Malyshev
Giedrius D
Stanislav Malyshev
Giedrius D
Andrew Minerd
Stanislav Malyshev
David Coallier
Chris#
Dmitry Stogov
nicobn
Chris#
Chrish
Dmitry Stogov
Andrei Zmievski
Stefan Priebsch
Stanislav Malyshev
Richard Lynch
Dmitry Stogov
Stanislav Malyshev
Andrei Zmievski
Stefan Priebsch
Stanislav Malyshev
Stefan Priebsch
Richard Lynch
Stefan Priebsch
Jani Taskinen
David Coallier
Robert Cummings
Richard Lynch
Stanislav Malyshev
Lukas Kahwe Smith
Derick Rethans
Stefan Priebsch
Stanislav Malyshev
Derick Rethans
Stanislav Malyshev
Stanislav Malyshev
Stanislav Malyshev
Dmitry Stogov
Stefan Priebsch
Dmitry Stogov
Jeremy Privett
Stanislav Malyshev
nicobn
Tony Bibbs
Stanislav Malyshev
Stefan Priebsch
David Coallier
Rich Buggy
Stanislav Malyshev
Stefan Priebsch
David Coallier
Dmitry Stogov
Andrei Zmievski
Hans Lellelid
dz
Guilherme Blanco
Alexey Zakhlestin
Stanislav Malyshev
Jeremy Privett
Dmitry Stogov
Arpad Ray
Dmitry Stogov
Stanislav Malyshev
Markus Fischer
David Coallier
Stanislav Malyshev
Brian Moon
Dmitry Stogov
Stanislav Malyshev
Brian Moon
Stanislav Malyshev
Dmitry Stogov
Stefan Walk
Dmitry Stogov
David Coallier
Dmitry Stogov
Stefan Priebsch
Stanislav Malyshev
Stefan Priebsch
Larry Garfield
Dmitry Stogov
Larry Garfield
Dmitry Stogov
Derick Rethans
Dmitry Stogov
nicobn
Sebastian Bergmann
Dmitry Stogov
nicobn
Rasmus Lerdorf
Lucas Nealan
Stefan Priebsch
Rasmus Lerdorf
Stefan Priebsch
Sebastian Bergmann
Stefan Priebsch
Dmitry Stogov
Sebastian Bergmann
Stanislav Malyshev
davidc
Stanislav Malyshev

Privacy Policy | Email Opt-out | Feedback | Syndication
© ActiveState Software Inc. All rights reserved