Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

array_unique failing on multidimensional array #50

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

Closed
philrennie wants to merge 1 commit into php-embed:master from philrennie:patch-1

Conversation

@philrennie
Copy link

@philrennie philrennie commented Feb 16, 2015

I found a particular soundcloud URL that was causing array_unique to throw a warning in getImages() (called via getImage()).

For the url https://soundcloud.com/calumfoad/sets/flaws-ep-stream the condition on line 76 was triggered and the resulting $images array after array_unshift would cause a php Notice: Array to string conversion once array_unique was called as array_unique does not cope with multidimensional array unless SORT_REGULAR is passed.

In all the other urls I tested the condition on line 76 was not triggered and the array returned from parent::getImages(), whilst multidimensional, only had a single element, array_unique returns instantly when passed a single element array and so does not raise the Notice.

Here's a basic test case with soundcloud urls that do and don't trigger the warning (I'm using composer)

getImage(); // This url causes array_unique in getImages() to throw a warning $info = Embed\Embed::create('https://soundcloud.com/calumfoad/sets/flaws-ep-stream'); $info->getImage();

I found a particular soundcloud URL that was causing array_unique to through a warning in getImages() (called via getImage()).
For the url https://soundcloud.com/calumfoad/sets/flaws-ep-stream the condition on line 76 was triggered and the resulting $images array after array_unshift would cause a php Notice: Array to string conversion once array_unique was called as array_unique does not cope with multidimensional array unless SORT_REGULAR is passed.
In all the other urls I tested the condition on line 76 was not triggered and the array returned from parent::getImages(), whilst multidimensional, only had a single element, array_unique returns instantly when passed a single element array and so does not raise the warning.
Here's a basic test case with soundcloud urls that do and don't trigger the warning (I'm using composer)
<?php
require_once('../vendor/autoload.php');
// This URL works fine
$info = Embed\Embed::create('http://www.soundcloud.com/bruceneilmusic');
$info->getImage();
// This url causes array_unique in getImages() to throw a warning
$info = Embed\Embed::create('https://soundcloud.com/calumfoad/sets/flaws-ep-stream');
$info->getImage();
Copy link
Collaborator

Hi. Thanks a lot for the feedback
I see the problem but the solution is a bit more complicated. getImages() always returns a multidimensional array because it returns not only the image url, but also the width, height and mime type. So the adapters that overwrite the getImages() method don't should call parent::getImages() because it returns all these information processed. The best way is to get a plain array with the images urls and fetch the mimetype and dimmensions at the end.
I'm going to fix this in the next commit.
😄

Copy link
Collaborator

Hi again. I've released the 2.0.1 version that fixes this issue.
Thank you.

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

Reviewers

No reviews

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

AltStyle によって変換されたページ (->オリジナル) /