[GH-ISSUE #130] setReturnType causes error #76

Closed
opened 2026-02-27 19:25:55 +03:00 by kerem · 1 comment
Owner

Originally created by @kasperkamperman on GitHub (Jun 14, 2018).
Original GitHub issue: https://github.com/jwilsson/spotify-web-api-php/issues/130

I try to set the return type to an associative array as mentioned in the changing return type example in the documentation.

$api = new SpotifyWebAPI\SpotifyWebAPI();
$api->setReturnType(SpotifyWebAPI::RETURN_ASSOC);
var_dump($api->getReturnType());

This gives me a: "Fatal error: Uncaught Error: Class 'SpotifyWebAPI' not found" error.

I include the class like this:

require_once('src/Request.php');
require_once('src/Session.php');
require_once('src/SpotifyWebAPI.php');
require_once('src/SpotifyWebAPIException.php');

I've found a work-around by using the string directly like

$api->setReturnType('assoc');
var_dump($api->getReturnType());

This works. However still curious why the mentioned constant can't be used.

Originally created by @kasperkamperman on GitHub (Jun 14, 2018). Original GitHub issue: https://github.com/jwilsson/spotify-web-api-php/issues/130 I try to set the return type to an associative array as mentioned in [the changing return type example](https://github.com/jwilsson/spotify-web-api-php/blob/b17682e6a1cf25c25c87a2a900cf6858a9c038b7/docs/examples/changing-return-type.md) in the documentation. ``` $api = new SpotifyWebAPI\SpotifyWebAPI(); $api->setReturnType(SpotifyWebAPI::RETURN_ASSOC); var_dump($api->getReturnType()); ``` This gives me a: "Fatal error: Uncaught Error: Class 'SpotifyWebAPI' not found" error. I include the class like this: ``` require_once('src/Request.php'); require_once('src/Session.php'); require_once('src/SpotifyWebAPI.php'); require_once('src/SpotifyWebAPIException.php'); ``` I've found a work-around by using the string directly like ``` $api->setReturnType('assoc'); var_dump($api->getReturnType()); ``` This works. However still curious why the mentioned constant can't be used.
kerem closed this issue 2026-02-27 19:25:55 +03:00
Author
Owner

@jwilsson commented on GitHub (Jun 14, 2018):

Hi!
My bad, that's an error in the docs. Adding the namespace should solve it.

$api = new SpotifyWebAPI\SpotifyWebAPI();
$api->setReturnType(SpotifyWebAPI\SpotifyWebAPI::RETURN_ASSOC);
var_dump($api->getReturnType());

And I'll get the docs updated.

<!-- gh-comment-id:397249218 --> @jwilsson commented on GitHub (Jun 14, 2018): Hi! My bad, that's an error in the docs. Adding the namespace should solve it. ```php $api = new SpotifyWebAPI\SpotifyWebAPI(); $api->setReturnType(SpotifyWebAPI\SpotifyWebAPI::RETURN_ASSOC); var_dump($api->getReturnType()); ``` And I'll get the docs updated.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/spotify-web-api-php#76
No description provided.