star2017 Posted March 26, 2017 Share Posted March 26, 2017 Hi, I am getting this error. I dont know how to troubleshoot it. I am using XAMPP on Windows 8.1 machine. Fatal error: Uncaught Error: Class 'xampp\php\pear\Product' not found in F:\xampp\htdocs\brackets-dev\index.php:11 Stack trace: #0 {main} thrown in F:\xampp\htdocs\brackets-dev\index.php on line 11 I have a class called Product in F:\xampp\php\pear\Product.php include_path=F:\xampp\php\PEAR (php.ini) <?php namespace \php\pear; # convencion: nombre NAMESPACE = nombre CARPETA contenedora class Product # convencion: nombre CLASE = nombre ARCHIVO { protected $name; public function __construct($name) { $this->name = $name; } } I am trying to instantiate this class in index.php which is in F:\xampp\htdocs\brackets-dev\index.php contains this code. <?php include 'Product.php'; use xampp\php\pear\Product; $product_one = new Product('colador'); I clearly have a issue with namespace definition and possibly use xampp\php\pear\Product I have tried many things. Googling a lot... and nothing. Help would be much much appreciated. Thank you. Quote Link to comment Share on other sites More sharing options...
Jacques1 Posted March 27, 2017 Share Posted March 27, 2017 You don't seem to understand the difference between namespaces and paths. The namespace you've chosen for your Product class is \php\pear There is no “xampp” anywhere, so your use statement is nonsensical. In any case, both your paths and the namespaces are very poor. Namespaces are supposed to be meaningful. For example, PSR-4 recommends using the top-level namespace for the vendor (e. g. your company). Sub namespaces can then be used to divide the vendor namespace into logical units: \YourCompany\Models\Product Why are you putting your own classes into the PEAR directory? Put them into your project into a sensible directory structure, set up an autoloader, and you're done. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.