php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #51469 why not Inner Classes?
Submitted: 2010-04-03 07:55 UTC Modified: 2015-09-08 00:24 UTC
Votes:4
Avg. Score:5.0 ± 0.0
Reproduced:4 of 4 (100.0%)
Same Version:1 (25.0%)
Same OS:1 (25.0%)
From: giorgio dot liscio at email dot it Assigned:
Status: Open Package: Class/Object related
PHP Version: 5.3.2 OS: irrelevant
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-04-03 07:55 UTC] giorgio dot liscio at email dot it
Description:
------------
hi, some object oriented architectures requires inner classes
i'm not good with english language so i write some examples:

in a library like PDO, now we can do some like this:

class Database
{
    public function prepareSql($sql){ return new Sql($sql)}
}

class Sql
{
    public function setValue($search, $replace){}
    public function executeQuery(){return new ExecutedQuery();}
}

class ExecutedQuery
{
    function fetch()
    function numRows()
    // etc
}

this api allows the developer to instantiate an ExecutedQuery with no Sql parameters escaping (class Sql)

so inner classes are useful to make visible classes in some trusted environment:

class Database
{
    public function prepareSql($sql){ return new Sql($sql)}

    class Sql
    {
        public function setValue($search, $replace){}
        public function executeQuery(){return new ExecutedQuery();}
        class ExecutedQuery
        {
            function fetch()
            function numRows()
            // etc
        }
    }
}

i've read a lot of rfc on php's wiki but no one talks about inner classes (useful like traits and others new work in progress features)

what do you think about this?


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2010-04-14 03:10 UTC] david71rj at gmail dot com
You can use namespaces from PHP 5.3, is basically this. See doc.
 [2010-04-14 10:55 UTC] giorgio dot liscio at email dot it
they are not, actually
 [2014-08-27 12:57 UTC] rausch dot nico at gmail dot com
Inner classes would be really great imho!
 [2015-09-08 00:24 UTC] cmb@php.net
FWIW: PHP 7 supports anonymous classes:
<http://www.php.net/manual/en/language.oop5.anonymous.php>.
 
PHP Copyright © 2001-2019 The PHP Group
All rights reserved.
Last updated: Wed Feb 20 01:01:26 2019 UTC