PHP Composer PSR-4 Startup and Subspaces, class not found

This question is independent, but I asked a similar question before: -

Composer gives an error, "Class Not Found"

The problem was resolved, but I could not explain the nesting problem. I thought it would be more appropriate to ask a new question.

I searched a lot, but I can't get nesting namespaces to work with psr-4 startup.

Directory structure: -

composer.jsonrun.php
├───src
│   ├───one
│   │       parentclass.php
│   │
│   └───twochildclass.php
└───vendorautoload.php
    └───composer
            autoload_classmap.php
            autoload_namespaces.php
            autoload_psr4.php
            autoload_real.php
            ClassLoader.php
            installed.json
            LICENSE

parentclass.php: -

<?php

namespace myns\one;

abstract class parentclass
{
    abstract public function abc();
}

childclass.php: -

namespace myns\two;

namespace myns\one;

use myns\one\parentclass as parentclass;

class childclass extends parentclass
{
    public function abc()
    {
        echo 'hello world';
    }
}

composer.json: -

{
    "name": "myvendor/mypackage",
    "description": "nothing",
    "authors": [
        {
            "name": "Omar Tariq",
            "email": "XXXXX@gmail.com"
        }
    ],
    "require": {},
    "autoload": {
        "psr-4": {
            "myns\\": "src/",
            "myns\\one\\": "src/one/",
            "myns\\two\\": "src/two/"
        }
    }
}

run.php: -

<?php

require_once __DIR__ . '/vendor/autoload.php';

use myns\two\childclass as childclass;

$childclass = new childclass();
$childclass->abc();

When I started php run.php. This gives an error: -

Fatal error: Class 'myns\two\childclass' not found in C:\wamp\...\run.php on line 7
0
source share
2 answers

. childclass.php, , , .

, namespace. , , .

myns\two;, namespace myns\two; .

+1

"autoload": {
    "psr-4": {
        "myns\\": "src/"
    }
}

, , , /src

0

All Articles