php-edifact / edifact-generator

Formatter for EDI messages
GNU Lesser General Public License v3.0
36 stars 29 forks source link

Errors running demo code #17

Open BemolRetail opened 3 years ago

BemolRetail commented 3 years ago

Dears,

I have a problem running VERMAS demo code from SAMPLES.md file. I have PHP 8.0.3. Can you please help

PHP Fatal error: Uncaught TypeError: EDI\Encoder::escapeValue(): Argument #1 ($str) must be of type string, int given, called in C:\0 - Dream\GDisk\000 - Work\003\019 -IATA\edifact-generator\vendor\sabas\edifact\src\EDI\Encoder.php on line 134 and defined in C:\0 - Dream\GDisk\000 - Work\003\019 -IATA\edifact-generator\vendor\sabas\edifact\src\EDI\Encoder.php:162 Stack trace:

0 C:\0 - Dream\GDisk\000 - Work\003\019 -IATA\edifact-generator\vendor\sabas\edifact\src\EDI\Encoder.php(134): EDI\Encoder->escapeValue(2)

1 C:\0 - Dream\GDisk\000 - Work\003\019 -IATA\edifact-generator\vendor\sabas\edifact\src\EDI\Encoder.php(101): EDI\Encoder->encodeSegment(Array)

2 C:\0 - Dream\GDisk\000 - Work\003\019 -IATA\edifact-generator\vendor\sabas\edifact\src\EDI\Encoder.php(77): EDI\Encoder->encode(Array, false)

3 C:\0 - Dream\GDisk\000 - Work\003\019 -IATA\edifact-generator\rbo.php(27): EDI\Encoder->__construct(Array, false)

4 {main}

thrown in C:\0 - Dream\GDisk\000 - Work\003\019 -IATA\edifact-generator\vendor\sabas\edifact\src\EDI\Encoder.php on line 162

Fatal error: Uncaught TypeError: EDI\Encoder::escapeValue(): Argument #1 ($str) must be of type string, int given, called in C:\0 - Dream\GDisk\000 - Work\003\019 -IATA\edifact-generator\vendor\sabas\edifact\src\EDI\Encoder.php on line 134 and defined in C:\0 - Dream\GDisk\000 - Work\003\019 -IATA\edifact-generator\vendor\sabas\edifact\src\EDI\Encoder.php:162 Stack trace:

0 C:\0 - Dream\GDisk\000 - Work\003\019 -IATA\edifact-generator\vendor\sabas\edifact\src\EDI\Encoder.php(134): EDI\Encoder->escapeValue(2)

1 C:\0 - Dream\GDisk\000 - Work\003\019 -IATA\edifact-generator\vendor\sabas\edifact\src\EDI\Encoder.php(101): EDI\Encoder->encodeSegment(Array)

2 C:\0 - Dream\GDisk\000 - Work\003\019 -IATA\edifact-generator\vendor\sabas\edifact\src\EDI\Encoder.php(77): EDI\Encoder->encode(Array, false)

3 C:\0 - Dream\GDisk\000 - Work\003\019 -IATA\edifact-generator\rbo.php(27): EDI\Encoder->__construct(Array, false)

4 {main}

thrown in C:\0 - Dream\GDisk\000 - Work\003\019 -IATA\edifact-generator\vendor\sabas\edifact\src\EDI\Encoder.php on line 162

sabas commented 3 years ago

Hello, are you using the latest version of the code or it has some changes? Because escapeValue() is on line 136 currently https://github.com/php-edifact/edifact/blob/master/src/EDI/Encoder.php

I tested the samples code right now and it is working... (although I'm on php 7.4.3 right now, guess I will upgrade :D )

Thanks, Stefano

BemolRetail commented 3 years ago

Hello,

I downgrade to PHP 7.4.16 same result. My steps:

  1. Install php
  2. install composter
  3. downloaded zip file with edifact-generator source and unpack
  4. install "php composer.phar install" using composter.json from zip file
  5. create rbo.php and copy there first sample from sample.md What am I doing wrong?
BemolRetail commented 3 years ago

Hi,

if I use only composer install without downloaded source I have the error

[RuntimeException] Could not scan for classes inside "src/" which does not appear to be a file nor a folder

sabas commented 3 years ago

Hi, my workflow is downloading it directly from composer through Packagist https://packagist.org/packages/php-edifact/edifact-generator#dev-master (this pulls also the other library)

https://packagist.org/packages/sabas/edifact#dev-master

then in the file <?php require('vendor/autoload.php');

and it works

My base composer.json is

{
    "require": {
        "sabas/edifact": "dev-master",
        "php-edifact/edifact-mapping": "dev-master",
        "php-edifact/edifact-generator": "dev-master"
    },
    "require-dev": {
        "kint-php/kint": "^3.3"
    }
}
BemolRetail commented 3 years ago

Dear Stefano,

Thank you very much. After update all samples work fine (VERMAS, CODECO, COPRAR, WESTIM, COHAOR, ORDERS) except COPINO. For COPINO I have the following error : PHP Fatal error: Access level to EDI\Generator\Copino::$sender must be protected (as in class EDI\Generator\Message) or weaker in C:\0 - Dream\GDisk\000 - Work\003\019 -IATA\generator4\vendor\php-edifact\edifact-generator\src\Generator\Copino.php on line 9

Fatal error: Access level to EDI\Generator\Copino::$sender must be protected (as in class EDI\Generator\Message) or weaker in C:\0 - Dream\GDisk\000 - Work\003\019 -IATA\generator4\vendor\php-edifact\edifact-generator\src\Generator\Copino.php on line 9

BemolRetail commented 3 years ago

Dear Stefano,

I change in Copino class variable from private to protected and now all code works fine. Thank you.

sabas commented 3 years ago

@BemolRetail thanks I'm glad you solved, I was away from the pc today. If you feel you may submit a pull request to fix it? :)