T
T
tester_toster2017-07-14 20:36:26
PHP
tester_toster, 2017-07-14 20:36:26

Why isn't one package class within another being generated when using composer to generate package autoload?

At the root of composer.json:

{
    "autoload": {
        "psr-4": {
          "VendorName\\test\\": "vendor\\VendorName\\test"
    	}
    }
}

Package in the vendors/VendorName\test folder;
There are 3 files in the root of the package:
A.php:
<?php
namespace VendorName\test;
Class A
{
  public function __construct()
        {
  }
}

B.php:
<?php
namespace VendorName\test;
use VendorName\test A as A;

Class B
{
  public function __construct()
        {
                return new A;
  }
}

And composer.json:
{
    "name": "VendorName/test",
    "description": "описание",
    "version": "версия",
    "license": "лицензия",
  "autoload": {
        "psr-4": {
            "VendorName\\test\\": ""
        }
    },
}

On creation: Throws an error:
var_dump(New VendorName\test\B);
Uncaught Error: Class 'VendorName\test\A' not found in C:\dev\testApp\vendor\VendorName\test\B.php

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexey Skobkin, 2017-07-14
@tester_toster

use VendorName\test A as A;
What are you trying to do here?
And what do the full paths to the A.php and B.php files look like?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question