Dymantic / laravel-instagram-feed

147 stars 51 forks source link

PHP version clash? #56

Open Jelte-ten-Holt opened 2 years ago

Jelte-ten-Holt commented 2 years ago

Hi, I'm trying to integrate your package with my project and I got the following errors in PHP. I was doing so well until then! Thanks for all your hard work. I'm running PHP 8.1.2

PHP Deprecated: Return type of Dymantic\InstagramFeed\InstagramFeed::getIterator() should either be compatible with IteratorAggregate::getIterator(): Traversable, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /home/forge/test.cyclotour.ch/vendor/dymantic/laravel-instagram-feed/src/InstagramFeed.php on line 42

PHP Deprecated: Return type of Dymantic\InstagramFeed\InstagramFeed::count() should either be compatible with Countable::count(): int, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /home/forge/test.cyclotour.ch/vendor/dymantic/laravel-instagram-feed/src/InstagramFeed.php on line 47

PHP Error: Class name must be a valid object or a string in /home/forge/test.cyclotour.ch/vendor/dymantic/laravel-instagram-feed/src/InstagramFeed.php on line 22

veceraj commented 2 years ago

@Jelte-ten-Holt Hi, I've been just now trying to implement this package too and ran into same error. If I understand correctly, this has nothing to do with the version of PHP.

For me, it was caused because the $profile was null and therefore creating new from null threw an error.

I recommend to try and validate that your instagram credentials are correct/up to date with todays api.

if (is_string($profile)) {
    $profile = Profile::for($profile);
}

return new $profile ? $profile->feed($limit) : self::empty();

Anyway, using the Profile::for and then the feed method gives you more options to handle this kind of an error in my opinion, you could also try to implement that.

$profile = Profile::for('profile');

$feed = $profile?->feed();
Jelte-ten-Holt commented 2 years ago

Hi @veceraj!

Thanks! And sorry for the slow response. I've been sick for the last few days. I'll try that! Cheers.

michaeljoyner commented 2 years ago

Hi @Jelte-ten-Holt have you managed to resolve your issue? If you are still having trouble, let me know and we can see if we can get it resolved.

@veceraj, thanks for helping out, it is appreciated.

Jelte-ten-Holt commented 2 years ago

Hi @michaeljoyner.

Thanks for taking an interest!

Yes, I did manage to resolve it. Though the PHP error does still show in some situations, it can be avoided with @veceraj 's suggestion. Also, even if the error is there, it does not impede the actual use of your wonderful package.

Cheers!