Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Warning: Use of undefined constant SOAP_1_2 - assumed 'SOAP_1_2' (this will throw an Error in a future version of PHP) #60

Closed
gasperkol opened this issue Dec 11, 2018 · 12 comments

Comments

@gasperkol
Copy link

Hi,

I've noticed this warning so I wondered if you can give this SOAP version in construct parameter of Vies class? or something like that that we can change version before the warning.

PHP version: 7.2.6

Thanks!

@DragonBe
Copy link
Owner

Hey @gasperkol,

I'll look into this immediately! Should not require a lots of time to fix.

@DragonBe
Copy link
Owner

OK @gasperkol , it looks I need some additional information here as the constant SOAP_1_1 and SOAP_1_2 are not giving me any errors or warnings.

php -derror_reporting=32767 -ddisplay_errors=1 -ddisplay_startup_errors=1 -r "echo SOAP_1_2 . PHP_EOL;"
2

Also the SoapClient documentation is not giving any hints that these constants will be removed any time soon.

That aside, if this issue is keep giving you warnings, we already provided a way to provide your own SoapClient with your custom settings.

$vies = new Vies();
$soapClient = new SoapClient($vies->getWsdl(), ['soap_version' => 2]);
$vies->setSoapClient($soapClient);

Or you can just provide the correct options directly:

$vies = new Vies();
$vies->setOptions(['soap_version' => 2]);

I hope this will help you sort out the issue. If not, provide me some additional information so I can better analyse where PHP is generating that warning.

@gasperkol
Copy link
Author

gasperkol commented Dec 11, 2018

Thanks for so quick reply!

Sorry for incomplete information.
So I've been using Symfony 3 and as I noticed now this is "Context check" from Symfony.

Uncaught PHP Exception Symfony\Component\Debug\Exception\ContextErrorException: "Warning: Use of undefined constant SOAP_1_2 - assumed 'SOAP_1_2' (this will throw an Error in a future version of PHP)"

So this warning still shows up because this version is set in _construct of Vies() and if I init this class this warning is triggered.

We can ignore this but if you can change this would be perfect!

If you need some additional information feel free to ask.

Thank you! @DragonBe

@DragonBe
Copy link
Owner

@gasperkol which version of this Vies package are you using?

@DragonBe
Copy link
Owner

@gasperkol OK, I was able to reproduce the warning even though I am not sure where we used the constant SOAP_1_2… but I'll figure it out! 😸

<?php
// File: /tmp/test.php
error_reporting(E_ALL|E_NOTICE|E_DEPRECATED);
ini_set('display_errors', 1);

var_dump(SOAP_1_1, SOAP_1_2);

When executing it with php /tmp/test.php I got the warning.

php /tmp/test.php
PHP Warning:  Use of undefined constant SOAP_2_1 - assumed 'SOAP_2_1' (this will throw an Error in a future version of PHP) in /tmp/test.php on line 8

Warning: Use of undefined constant SOAP_2_1 - assumed 'SOAP_2_1' (this will throw an Error in a future version of PHP) in /tmp/test.php on line 8
int(1)
int(2)

Interesting note: it only throws this warning for version 2, not for 1… not sure why 🤔

@gasperkol
Copy link
Author

@DragonBe I use version 1.0.1.

If I understand correctly this warning is thrown when some global constant is not set and its become string....
So if you find this SOAP_1_2 constant (and I know you will 😸) where you use it then you can check why is not set.

** Sory to bother with this warning but in Symfony is annoying when you have warning in DEV ENV 😉

DragonBe added a commit that referenced this issue Dec 11, 2018
Please look at issue #60 on [GitHub](#60) to see what's going on
@DragonBe
Copy link
Owner

Very strange situation which I need to investigate further, but once I've instantiated SoapClient with a specific version, the error I was able to reproduce was no longer there. I assume that somewhere it became defined (this is what I need to investigate 🧐further).

@gasperkol can I ask something of you? I have a branch where the unit tests are digging deeper into this subject (see https://github.com/DragonBe/vies/tree/michelangelo/issue-60-warning-for-not-defined-soap-version). Can you check this branch out and run ./vendor/bin/phpunit. The output is what I'm interested in.

If you have issues running PHPUnit, I've included docker containers to make life easier: I've got them for PHP 7.0, 7.1, 7.2 and 7.3.

Getting started quickly:

docker build -t phpunit:7.1 .docker/php7.1

  <<<building container here>>>

docker run --rm -t -i phpunit:7.1 ./vendor/bin/phpunit

When I ran it, no issues were reported even though I've been testing all sorts of usages of these constants converting the notices and warnings into exceptions.

PHPUnit 7.5.0 by Sebastian Bergmann and contributors.

...............................................................  63 / 210 ( 30%)
............................................................... 126 / 210 ( 60%)
............................................................... 189 / 210 ( 90%)
.....................                                           210 / 210 (100%)

Time: 8.11 seconds, Memory: 12.00MB

OK (210 tests, 404 assertions)

Generating code coverage report in Clover XML format ... done

Generating code coverage report in HTML format ... done

@gasperkol
Copy link
Author

@DragonBe Now I played with my code and settings and I noticed that only in Vies version 1.0.1 this warning shows up. In any others versions everything is ok.

And this version where you added this tests works without warning 😄 ..

And test result:
screen shot 2018-12-12 at 07 05 48

So for me, a solution is to update to latest 1.X or 2.X version and everything works.
If you still need some additional information please let me know.

Thank you!

@DragonBe
Copy link
Owner

OK, thank you for your feedback @gasperkol. Let me know if you were able to upgrade and if those warnings no longer appear.

To be on the safe side, I will include those additional tests in the code base in case future versions of PHP might break things.

For your reference, I'm running this package on PHP 7.3.0 and it works like a charm 🌟

@gasperkol
Copy link
Author

@DragonBe Yes I upgraded to 1.0.6 and 1.0.9 and now everything works without warnings 😃

Thank you for time and debugging.

And thank you for this package is a real time saver 😉

@DragonBe
Copy link
Owner

Merged in the additional unit tests for this use case in commit c7d4d0a.

@DragonBe
Copy link
Owner

@gasperkol you're very welcome. Thank you for reporting it, this way I learn about the things I don't know and makes me wiser along the way.

Have a nice day 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants