Edit report at https://bugs.php.net/bug.php?id=70187&edit=1
ID: 70187
Updated by: nikic@php.net
Reported by: pagescene at gmail dot com
Summary: [Introduced in PHP 7] Notice: unserialize():
Unexpected end of serialized data
Status: Verified
Type: Bug
Package: Unknown/Other Function
Operating System: Windows 7
PHP Version: 7.0.0beta2
-Assigned To:
+Assigned To: dmitry
Block user comment: N
Private report: N
New Comment:
@pagescene: This is definitely a bug in PHP 7. You shouldn't change the Drupal code for this ;)
The problem is basically that in PHP 7 count($array) is no longer precise (i.e. does not match the
actual number of elements in the array) in some very limited circumstances. One such case is doing
something like count($object->getAllProperties()) if there exists some property that was declared
on the class and later unset(). In this case the count() will be reported to be one larger than it
really is.
@dmitry: Could you take a look at this? Is there some way to fix this short of doing a full table
scan beforehand (or serializing the contents into a separate buffer first and counting elements
while doing so)?
Previous Comments:
------------------------------------------------------------------------
[2015-08-25 09:22:10] pagescene at gmail dot com
Thanks very much to you all for looking into this issue.
So do you think this is a PHP 7 bug or does the Drupal Views code need to be adjusted for PHP 7?
The error appears only under PHP 7.
@nikic@php.net, would you please explain this part from your comment:
"t's because there is an object with a dynamic properties HT, which contains and INDIRECT
to and UNDEF" ..
The View's class definition is here (expand View source item in page):
https://api.drupal.org/api/views/includes%21view.inc/7
The ctools_object_cache code (where the view's object gets serialized):
http://www.drupalcontrib.org/api/drupal/contributions%21ctools%21includes%21object-cache.inc/7
Thanks.
------------------------------------------------------------------------
[2015-08-23 17:42:55] nikic@php.net
Here we go: https://3v4l.org/KiLqN
class A { public $b; }
$a = new A;
var_dump($a); // force properties HT
unset($a->b);
var_dump(serialize($a));
Results in "O:1:"A":1:{}" while it should be "O:1:"A":0:{}".
------------------------------------------------------------------------
[2015-08-23 17:40:53] nikic@php.net
If I were to venture a guess, it's because there is an object with a dynamic properties HT,
which contains and INDIRECT to and UNDEF. The hashtable count will then include the UNDEF, but it
will not be actually present in the properties list.
------------------------------------------------------------------------
[2015-08-23 16:43:27] cmb@php.net
For some reason the serialized string is corrupt. Both
view_display objects declare to have 8 properties, but they only
have 7. The views_display object declares to have 55 properties,
but it has only 51. Fixing these issues manually lets
unserialize() succeed, see <https://3v4l.org/Pvr91>.
So obviously, this is not an issue with unserialize(), but rather
with serialize(). It would be helpful to have a minimal reproduce
script.
------------------------------------------------------------------------
[2015-08-23 15:56:45] jhdxr@php.net
I tried to unserialize your string <https://3v4l.org/EYtah>, but failed in all php version,
including php5.6. Is there any invisible characters in your original string?
------------------------------------------------------------------------
The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at
https://bugs.php.net/bug.php?id=70187
--
Edit this bug report at https://bugs.php.net/bug.php?id=70187&edit=1