PHP's serialize() function fails to store a good representation of an edited view under PHP 7 (inc. beta 3). It produces a serialized string but for some or other reason that string cannot be un-serialized again (it gives offset errors at un-serialization).

This makes it impossible to add new views or edit exiting ones (which were created originally under earlier PHP versions).

Strangely enough, no similar problem can be seen under PHP 5.6, only under PHP 7.

The functions where the problem is located:

ctools_object_cache_get() {..}
ctools_object_cache_set() {..}

No similar issue can be seen under PHP 7 & Drupal 8.

Any idea what might be going on here? Thanks.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

W.M. created an issue. See original summary.

W.M.’s picture

Title: Serialized storage of a new / existent view under PHP 7 fails » Serialized storage of a new / existent view fails under PHP 7
lsokolowski’s picture

also got this problem with php 7 beta 3

bnobleman’s picture

Related:
https://www.drupal.org/node/2534298

Also, there is one issue submitted against unserialize function in php 7

====
Drupal Training in Beijing
http://www.nobleprog.cn/drupal-peixun

W.M.’s picture

Update:

I have tried to solve the issue by using an alternative to serialize(), namely igbinary_serialize() for PHP 7. Still cannot save / edit views but this alternative serialization library sheds more light on the original cause of the problem under PHP 7:

I get this error message when I try to save or edit a view:

Fatal error: views_ui_edit_page_title(): The script tried to execute a method or access a property of an incomplete object. Please ensure that the class definition "view" of the object you are trying to operate on was loaded _before_ unserialize() gets called or provide a __autoload() function to load the class definition in DRUPAL_ROOT\sites\all\modules\views\views_ui.module on line 271

I hope this information helps us to solve the issue.

EclipseGc’s picture

Status: Active » Postponed

I don't have a good way to test php7 right now, let me take this up with the other ctools maintainers and have a conversation.

W.M.’s picture

@EclipseGc

Thanks very much.

What I have noticed also under PHP 7 is that the view's object has a different structure than the one under PHP 5.6. Properties such as "attachment_before", "attachment_after", "build_info" were placed under PHP 7 at root view's object level rather than attached to particular displays.

I will happily test any patches / ideas and report results.

neclimdul’s picture

That's actually really helpful. I haven't looked at it but I am guessing its running into this change.
https://wiki.php.net/rfc/uniform_variable_syntax

W.M.’s picture

Here are two text files that contain the results of var_dump of the view's object before it gets serialized and stored inside ctools_object_cache table (i.e. while editing the view).

As can be seen some properties change position inside the view's object under the two different versions of PHP. For example:

PHP 5.6.12:

object(view)->built @ line 542

PHP 7.beta.3:

object(view)->built @ line 24

Importantly, while producing these two var_dumps I was doing the same exact change to the view: to set AJAX from off to on.

I also get this warning under PHP 7:

Deprecated function: Methods with the same name as their class will not be constructors in a future version of PHP; views_display has a deprecated constructor in require_once() (line 127 of C:\WWW\drupal\sites\all\modules\ctools\ctools.module).

I hope this information will prove helpful.

W.M.’s picture

Problem still can be seen under the latest PHP 7 release (7.0.0RC1). Saving a view fails with the warnings:

Notice: unserialize(): Unexpected end of serialized data in ctools_object_cache_get() (line 48 of C:\WWW\drupal\sites\all\modules\ctools\includes\object-cache.inc).
Notice: unserialize(): Error at offset 12656 of 14361 bytes in ctools_object_cache_get() (line 48 of C:\WWW\drupal\sites\all\modules\ctools\includes\object-cache.inc).
W.M.’s picture

The issue/bug is discussed also here at PHP's bug reports:

https://bugs.php.net/bug.php?id=70187

W.M.’s picture

Status: Postponed » Closed (works as designed)

Issue fixed. The problem was due to a bug in PHP 7 source code. PHP team fixed the issue. The next preview release of PHP 7 should include the fix.

I can confirm that PHP-SRC as per today (custom local compilation under Linux) does not produce the above mentioned error, Views works fine now under current in-development PHP-7.

EclipseGc’s picture

That's great, but perhaps we should consider filing a follow up that removes the non-__construct() style constructor methods in favor of real __construct methods?

Eclipse

heddn’s picture