0

I am trying to create a basic class and running it from CLI using this command :

php -r 'include "src/main.php"; main::count_by_vendor_id();'

In the constructor of this main class I am initializing another class, but its showing me this error.

PHP Fatal error:  Uncaught Error: Class 'App\HttpRequestData' not found in 
/var/www/MetroLiveCodingChallenge/src/main.php:12
Stack trace:
#0 /var/www/MetroLiveCodingChallenge/src/main.php(34): App\main->__construct()
#1 Command line code(1): include('/var/www/MetroL...')
#2 {main}
thrown in /var/www/MetroLiveCodingChallenge/src/main.php on line 12

This is my main class :

<?php

namespace App;

require 'vendor/autoload.php';

class main{

private $dataReader;

public function __construct(){
        $request = new \App\HttpRequestData();
        $response = $request->fetchData();

        $this->dataReader = new JsonReader();

        $this->collection = $this->dataReader->read($response);
}

public function count_by_price_range(int $minPrice, int $maxPrice): void
{


}

public function count_by_vendor_id(): void
{
    echo
    print('I am inside count by vendor');
}

}

new main();

This is my HTTPRequestData class :

<?php

namespace App;

class HttpRequestData
{
}
IMSoP
  • 89,526
  • 13
  • 117
  • 169
Syed Abdur Rehman Kazmi
  • 1,640
  • 3
  • 13
  • 30
  • 1
    What is the file name of the `HTTPRequestData` class? What is your autoloader configuration - I'm guessing from 'vendor/autoload.php' that you're using Composer, and have an ["autoload" section in composer.json](https://getcomposer.org/doc/04-schema.md#autoload)? – IMSoP Dec 14 '21 at 12:07

0 Answers0