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: 2021-03-02 11:00 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: Suspended Package: Class/Object related
PHP Version: 5.3.2 OS: irrelevant
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [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>.
 [2021-03-02 11:00 UTC] cmb@php.net
-Status: Open +Status: Suspended
 [2021-03-02 11:00 UTC] cmb@php.net
If anybody is still interested in support for inner classes,
please pursue the RFC process[1].  For the time being, I'm
suspending this ticket.

[1] <https://wiki.php.net/rfc/howto>
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Mar 19 02:01:28 2024 UTC