dvdoug / BoxPacker

4D bin packing / knapsack problem solver
MIT License
612 stars 156 forks source link

Can't initialize class (not found). Composer problem? #559

Closed r-martins closed 12 months ago

r-martins commented 1 year ago

I'm just trying to run the first documentation example...

So, I ran the composer require dvdoug/boxpacker, and created an example1.php in the project's folder (vendor's parent) as follows:

<?php
require __DIR__ . '/vendor/autoload.php';
use DVDoug\BoxPacker\Rotation;
use DVDoug\BoxPacker\Packer;
use DVDoug\BoxPacker\Test\TestBox; // use your own `Item` implementation
use DVDoug\BoxPacker\Test\TestItem; // use your own `Item` implementation

$packer = new Packer();

/*
 * Add choices of box type - in this example the dimensions are passed in directly via constructor,
 * but for real code you would probably pass in objects retrieved from a database instead
 */
$packer->addBox(
    new TestBox(
        reference: 'Le petite box',
        outerWidth: 300,
        outerLength: 300,
        outerDepth: 10,
        emptyWeight: 10,
        innerWidth: 296,
        innerLength: 296,
        innerDepth: 8,
        maxWeight: 1000
    )
);
...

But I'm always getting the error bellow:

root@a7672a0b58c9:/var/www/html# php example1.php

Fatal error: Uncaught Error: Class "MyBox" not found in /var/www/html/example1.php on line 15

Error: Class "MyBox" not found in /var/www/html/example1.php on line 15

Call Stack: 0.0008 405112 1. {main}() /var/www/html/example1.php:0

PhpStorm can map the classes with no problem, but for some misconfiguration in the project, I think this error is happening.

It doesn't happen if I try to use other packing libraries, like cloudstek/php-laff.

I'm using version 3.12.0. Downgrading to 3.11.* solves the problem.

Any Idea?

dvdoug commented 1 year ago

Hi

Since MyBox is your class and not from this library, I can't see how this is a BoxPacker issue, but happy to try and help - the code you've pasted above doesn't reference MyBox though?