phpfui / ConstantContact

MIT License
16 stars 7 forks source link

Client::session() Return value must be of type string, null returned #12

Closed bright-cloud-studio closed 1 year ago

bright-cloud-studio commented 1 year ago

Hi there,

I am using this awesome library here to add Constant Contact API integration with Contao. I am having this error setting up the initial connection. The crazy thing is, it works as expected and it does establish my connection, it just happens that Contao crashes at the same time. I have seen this error a lot recently and I think it might have something to do with PHP 8.1. This is the error I am getting:

[2022-12-06T19:35:16.951748+00:00] request.CRITICAL: Uncaught PHP Exception TypeError: "PHPFUI\ConstantContact\Client::session(): Return value must be of type string, null returned" at /home/framework/public_html/vendor/phpfui/constantcontact/src/ConstantContact/Client.php line 500 {"exception":"[object] (TypeError(code: 0): PHPFUI\\ConstantContact\\Client::session(): Return value must be of type string, null returned at /home/framework/public_html/vendor/phpfui/constantcontact/src/ConstantContact/Client.php:500)"} []

phpfui commented 1 year ago

Thanks. Will look into it. I have not run the library through all possible paths, so this could be a day one issue. I should have something by Friday.

bright-cloud-studio commented 1 year ago

That is great, thanks so much. This has been a really fun project and it has only been possible due to this project of your, I really appreciate it.

We have run into this issue so many times recently when updating to the latest Contao 4.13 which requires PHP 8.0 or higher, they made a change where you basically can't pass null. I think this would be easily fixed by just writing a manual check "If null, ignore", I've had to do it over and over updating custom projects to the newer PHP version.

If your busy, I can possibly try and hunt the link down and push an edit myself, but I will be patient and look out for your update.

Thanks again.

phpfui commented 1 year ago

I just looked a the code. I require session support to be turned on. Make sure that is on. Will try to see if I can figure out a way to require it in composer. If session support is on, try hacking line 492 of Client.php to:

$value = $_SESSION[$key] ?? '';

I will add that in the next release (Thursday I hope for PHP 8.2 support).

Also just FYI, it looks like you might be including the vendor directory in the public_html directory, which is BAD!!!! If so, move composer.json to /home/framework, the do composer install from that directory. You will just need to change your autoload.php include path and the rest should work.

bright-cloud-studio commented 1 year ago

Session support is on, I am doing all of this through the Contao CMS and it would not work without it. I tried calling it just to be sure and it didn't make a difference.

As for vendor being in public_html, that is how Contao does it. They have you change the root directory to 'public_html/web' during installation, composer and their packages sit one up from that in what is usually the root 'public_html'. Thanks for the advice though, much appreciated.

I will try this fix for now and let you know how it goes.

phpfui commented 1 year ago

Good to know. Check out the Client::setSessionHandler as well.

I will be releasing a PHP 8.2 version today or tomorrow. Let me know what you find.

Thanks

bright-cloud-studio commented 1 year ago

Perfect, that fix did work. Thanks. I will update to the official release once its out.

phpfui commented 1 year ago

New release available. Thanks for the heads up on this.