php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #52297 visibility identifier namespace-protected
Submitted: 2010-07-09 02:56 UTC Modified: 2010-07-16 07:09 UTC
Votes:16
Avg. Score:4.6 ± 1.1
Reproduced:14 of 14 (100.0%)
Same Version:10 (71.4%)
Same OS:11 (78.6%)
From: giorgio dot liscio at email dot it Assigned:
Status: Wont fix Package: Class/Object related
PHP Version: 5.3.2 OS: all
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: giorgio dot liscio at email dot it
New email:
PHP Version: OS:

 

 [2010-07-09 02:56 UTC] giorgio dot liscio at email dot it
Description:
------------
hi, in php is missing a visibility identifier to protect methods and properties inside the namespace

example:

namespace Oracle;  // abstraction layer for Oracle

class Connection
{
    // ociresource should be visible only in the namespace
    // in php 5.3 the property is public to world
    namespace-protected $ociresource;

    public function __construct()
    {
         $this->ociresource = oci_connect();
    }
    public function query($sql)
    {
         return new Query($this, $sql);
    }
}

class Query
{
    public function __construct(Connection $con, $sql)
    {
         $x = oci_parse($con->ociresource, $sql);    // $ociresource is accessible only in this namespace
         oci_execute($x);
    }
}

----

suggested visibility identifier:

namespace-private
    (if namespace is \Test\Abc\ the method/property is only accessible within \Test\Abc\)
namespace-protected
    (if namespace is \Test\Abc\ the method/property can be accessible within \Test\Abc\ and, for example \Test\Abc\Foo\ )


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2010-07-16 07:09 UTC] aharvey@php.net
-Status: Open +Status: Wont fix
 [2010-07-16 07:09 UTC] aharvey@php.net
PHP namespaces really aren't meant to be anything more than a way of
avoiding name collisions and allowing aliasing -- visibility modifiers
are somewhat beyond the scope of what they're trying to achieve.

If you really want to push this, I'd suggest raising this on the
Internals mailing list (preferably with a prototype patch) with a view
to putting this through the RFC process instead, given it would be a
moderately significant language change.
 [2010-07-16 14:03 UTC] giorgio dot liscio at email dot it
hi aharvey
i really want to contribute but my English is not good
i hope someone want to write an rfc

for anyone reads: feel free to write comments about this
 [2011-03-30 11:59 UTC] florent dot biville at insa-rouen dot fr
I agree such a modifier is necessary.

From an API designer point of view, how would it be possible to distinct API classes/methods from classes/methods needed within (and only within) the framework without this ?

This current limitation leads to unsafe overrides of internal classes/methods.

Since PHP 5.3 now embeds namespaces, this modifier must be available.
 
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Thu Jul 29 06:01:24 2021 UTC