The following error is generated on servers using PHP version 5.3 or lower when using a Flickr Photo field on a node.
Notice: Uninitialized string offset: 0 in flickr_img() (line 320 of /myDrupalSite/sites/all/modules/contrib/flickr/flickr.inc).
On servers using PHP version 5.4 and higher, this error does not occur. After searching a bit, I've found this in regards to differences in the offset handling for php and believe this is the cause of the issue:
http://php.net/manual/en/migration54.incompatible.php
Non-numeric string offsets - e.g. $a['foo'] where $a is a string - now return false on isset() and true on empty(), and produce a E_WARNING if you try to use them. Offsets of types double, bool and null produce a E_NOTICE. Numeric strings (e.g. $a['2']) still work as before. Note that offsets like '12.3' and '5 foobar' are considered non-numeric and produce a E_WARNING, but are converted to 12 and 5 respectively, for backward compatibility reasons. Note: Following code returns different result. $str='abc';var_dump(isset($str['x'])); // false for PHP 5.4 or later, but true for 5.3 or less
To re-create simply add the Flickr Photo field to any content type. Create new content selecting Item Type "photo", Fill in the Item id and User Id fields, and save. When you view the page you will see the error.
Note: This issue was first reported (along with other items) in my issue on this page: https://www.drupal.org/node/2493597
| Comment | File | Size | Author |
|---|---|---|---|
| #5 | flickr-string_offset_fix-2493707-5.patch | 690 bytes | ladybug_3777 |
Comments
Comment #1
ladybug_3777 commentedIn case it helps, these are the exact versions of PHP I am using:
The server that is not showing the error has PHP version 5.4.6.
The server that is showing the error is PHP version 5.3.5
Comment #2
lolandese commentedYou pinpointed the cause already. Nice.
Can you do some experiments? Enable Devel and replace:
$date_taken = isset($info['dates']['taken']) ? $info['dates']['taken'] : $photo['dates']['taken'];with
or
Comment #3
lolandese commentedForget #2 and try to replace line 320 of myDrupalSite/sites/all/modules/contrib/flickr/flickr.inc with:
$date_taken = is_array($info) && isset($info['dates']['taken']) ? $info['dates']['taken'] : $photo['dates']['taken'];or
$date_taken = is_array($info['dates']) && isset($info['dates']['taken']) ? $info['dates']['taken'] : $photo['dates']['taken'];See http://stackoverflow.com/a/15368076/523688.
Comment #4
ladybug_3777 commentedSorry was away on the holiday weekend. I will give this a try for you today and report back.
Comment #5
ladybug_3777 commentedOk, I tried your first suggestion (on comment #3) and that worked great on both versions of PHP. The second option produced an error.
If that's the only spot that needs to be fixed up then you can use the attached patch. Thanks!
Comment #7
lolandese commentedNice you tested in both versions of PHP.
Thanks.
Comment #8
lolandese commented