# [RFC] Specify namespace to include file into.

- Thread: https://externals.io/message/58785
- Original archive: https://news-web.php.net/php.internals/58785
- Started by Michael Morris on 2012-03-08T16:05:19+00:00
- Messages: 9
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · RFCs at https://externals.io/rfc.md · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #58785 — Michael Morris — 2012-03-08T16:05:19+00:00

URL: https://externals.io/message/58785#58785

https://wiki.php.net/rfc/changes_to_include_and_require

Since the reaction to the first of the two suggestions was largely
negative I've withdrawn it for now to focus on the second of the two
changes.  In all honestly, these two suggestions should have had
independent RFC's from the start.

Of the two suggestions this one has the more profound implications to
the language even if it is simpler to implement.  Thoughts?

---

## #58787 — Gustavo Lopes — 2012-03-08T16:23:03+00:00

URL: https://externals.io/message/58785#58787 · In reply to: #58785

On Thu, 08 Mar 2012 17:05:19 +0100, Michael Morris  
<dmgx.michael@gmail.com> wrote:

> https://wiki.php.net/rfc/changes_to_include_and_require
>
> Since the reaction to the first of the two suggestions was largely
> negative I've withdrawn it for now to focus on the second of the two
> changes.  In all honestly, these two suggestions should have had
> independent RFC's from the start.
>
> Of the two suggestions this one has the more profound implications to
> the language even if it is simpler to implement.  Thoughts?
>

How exactly would this be useful?

The purpose of namespaces is to avoid collision of symbols.  Are you  
saying they did not solve this problem and you have to rename already  
namespaced files?

I also don't understand your template argument. Why would you need to  
namespace templates? Typically they are included from inside a function  
(and therefore don't change/access the global namespace).

I only see some usefulness as a transitional measure, which would save  
 from namespacing 'legacy' libraries. But PHP 5.5 seems a bit late to  
introduce such measure.

-- 
Gustavo Lopes

---

## #58788 — Anthony Ferrara — 2012-03-08T16:25:03+00:00

URL: https://externals.io/message/58785#58788 · In reply to: #58785

Michael,

Quick question:  how would this work with require_once?

Let's say that I have a class Foo defined in a file without a
namespace declaration.

What happens if I require_once with a namespace first (so Foo gets
imported into the namespace), and then require_once later without a
namespace?  Should it require twice?  Which then could break things
(if there was procedural or initialization code in there)...  If not,
then you won't have Foo in the root namespace, and lead to other
errors.

Anthony


> https://wiki.php.net/rfc/changes_to_include_and_require
>
> Since the reaction to the first of the two suggestions was largely
> negative I've withdrawn it for now to focus on the second of the two
> changes.  In all honestly, these two suggestions should have had
> independent RFC's from the start.
>
> Of the two suggestions this one has the more profound implications to
> the language even if it is simpler to implement.  Thoughts?

---

## #58789 — Ralph Schindler — 2012-03-08T16:30:09+00:00

URL: https://externals.io/message/58785#58789 · In reply to: #58785

At first glance, this is technically impossible, with regards to our 
current resolution rules: 
http://php.net/manual/en/language.namespaces.rules.php

Assuming you have an un-namespaced:

class Db {
   public function __construct() {
     $this->conn = new PDO(..);
   }
}

and you require this as:

require ./path/to/Db.php, 'Some\SubDb';

How does PDO get resolved? Automatically as \PDO or as \Some\SubDb\PDO?

Isn't it just easier to change the code? ;)

-ralph



> https://wiki.php.net/rfc/changes_to_include_and_require
>
> Since the reaction to the first of the two suggestions was largely
> negative I've withdrawn it for now to focus on the second of the two
> changes.  In all honestly, these two suggestions should have had
> independent RFC's from the start.
>
> Of the two suggestions this one has the more profound implications to
> the language even if it is simpler to implement.  Thoughts?

---

## #58790 — Sebastian Bergmann — 2012-03-08T16:30:45+00:00

URL: https://externals.io/message/58785#58790 · In reply to: #58785

Am 08.03.2012 17:05, schrieb Michael Morris:
> Thoughts?

 Sounds pointless/useless to me.

-- 
Sebastian Bergmann                    Co-Founder and Principal Consultant
http://sebastian-bergmann.de/                           http://thePHP.cc/

---

## #58792 — Pierre Joye — 2012-03-08T17:01:44+00:00

URL: https://externals.io/message/58785#58792 · In reply to: #58790

> Am 08.03.2012 17:05, schrieb Michael Morris:
> > […]
>
>  Sounds pointless/useless to me.

Could you answer more than one liner to RFCs? Even if you totally
disagree with the idea(s) behind it. Thanks.

Cheers,
-- 
Pierre

@pierrejoye | http://blog.thepimp.net | http://www.libgd.org

---

## #58793 — Simon Schick — 2012-03-08T17:03:49+00:00

URL: https://externals.io/message/58785#58793 · In reply to: #58790

2012/3/8 Sebastian Bergmann <sebastian@php.net>:
> Am 08.03.2012 17:05, schrieb Michael Morris:
> > […]
>
>  Sounds pointless/useless to me.
>
> --
> Sebastian Bergmann                    Co-Founder and Principal Consultant
> http://sebastian-bergmann.de/                           http://thePHP.cc/
>
> --
> 
> 
>

Hi,

I understand the point why you wanna use that ... but I think
personally it does not seem to be implementable, if you'd ask me.
There are too many things we would have to change or specify a behavior for ...

* what if the included file contains direct code or a bunch of functions?
* what about *_once file-includes inside this files?
* what if the included file provides an auto-class-loader?

If you just have class-files and not direct code there are still some
opened questions ...

The idea makes sense to me, but currently there are too much opened
questions for me to take a closer look at it.

Bye
Simon

---

## #58794 — Simon Schick — 2012-03-08T17:08:14+00:00

URL: https://externals.io/message/58785#58794 · In reply to: #58790

2012/3/8 Sebastian Bergmann <sebastian@php.net>:
> Am 08.03.2012 17:05, schrieb Michael Morris:
> > […]
>
>  Sounds pointless/useless to me.
>
> --
> Sebastian Bergmann                    Co-Founder and Principal Consultant
> http://sebastian-bergmann.de/                           http://thePHP.cc/
>
> --
> 
> 
>

Hi,

I understand why you want to have this feature ...
Let me just put a view questions in here:

* what if the included file contains direct code or a bunch of functions?
* what about *_once file-includes inside this files?
* what if the included file provides an auto-class-loader?

If you just have class-files and not direct code there are still some
opened questions ...

The idea makes sense to me, but currently there are too much opened
questions for me to take a closer look at it.

Bye
Simon

---

## #58795 — Gustavo Lopes — 2012-03-08T17:22:33+00:00

URL: https://externals.io/message/58785#58795 · In reply to: #58789

On Thu, 08 Mar 2012 17:51:34 +0100, Michael Morris  
<dmgx.michael@gmail.com> wrote

> > […]
>
> You forget that variable scope and namespace scope have absolutely
> nothing to do with each other.  At all.  If I have a template that
> needs to call a function from within my project's namespace it must
> either use the fully qualified name of the function or it must declare
> the namespace it is part of on the first line.

Sorry, I confused things here for a moment. This in fact seems to be a  
valid use case. But you're only saving a line, and you can't rely on the  
fallback to globals because it would create an ambiguity.

-- 
Gustavo Lopes
