jchristopher / attachments

[WordPress Plugin] Attachments allows you to simply append any number of items from your WordPress Media Library to Posts, Pages, and Custom Post Types
wordpress.org/extend/plugins/attachments/
GNU General Public License v2.0
241 stars 78 forks source link

HHVM problem, Call to undefined method #146

Closed codeaken closed 6 years ago

codeaken commented 9 years ago

When running this plugin under HHVM I get "white screen of death" in the admin. These are the errors I find in the log:

[Wed Jun 24 11:21:40 2015] [hphp] [32591:7fa145fff700:9:000001] [] \nWarning: No such file or directory in /var/www/6199fc67/wp-includes/pomo/streams.php on line 224
[Wed Jun 24 11:21:41 2015] [hphp] [32591:7fa145fff700:9:000002] [] \nFatal error: Call to undefined method Walker_PageDropdown::format_value_for_input() in /var/www/6199fc67/wp-content/plugins/attachments/classes/class.attachments.php on line 1293

Disabling this plugin makes the admin work as expected again.

Plugin version: 3.5.5 Wordpress version: 4.2.2

kaiwa commented 9 years ago

Same here. The reason is that the field types are mapped to the wrong classes.

With PHP

[
    ...
    "wysiwig" => "Attachments_Field_WYSIWIG"
    ...
]

With HHVM

[
    ...
    "wysiwig" => "Walker_PageDropdown"
    ...
]

I suppose HHVM sorts the return array of get_declared_classes() in a different way than PHP, so this a litte bit unconventional method of finding the class seems to crash:

                    // determine it's class
                    $flag = array_search( 'Attachments_Field', $existing_classes );

                    // the field's class is next
                    $field_class = $existing_classes[$flag + $field_index + 1];
kaiwa commented 9 years ago

Wouldn't it be possible to also specify the class names instead of trying to determine them?

        function get_field_types()
        {
            $field_types = array(
                'text' => array(
                    'path'  => ATTACHMENTS_DIR . 'classes/fields/class.field.text.php', 
                    'class' => 'Attachments_Field_Text'
                ),
                'textarea' => array(
                    'path'  => ATTACHMENTS_DIR . 'classes/fields/class.field.textarea.php',
                    'class' => 'Attachments_Field_Textarea'
                ),
                'select' => array(
                    'path'  => ATTACHMENTS_DIR . 'classes/fields/class.field.select.php',
                    'class' => 'Attachments_Field_Select'
                ),
                'wysiwyg' => array(
                    'path'  => ATTACHMENTS_DIR . 'classes/fields/class.field.wysiwyg.php',
                    'class' => 'Attachments_Field_WYSIWYG'
                )
            );

            // support custom field types
            // $field_types = apply_filters( 'attachments_fields', $field_types );

            foreach( $field_types as $name => $type)
            {
                // proceed with inclusion
                if( file_exists( $type['path'] ) )
                {
                    // include the file
                    include_once( $type['path'] );

                    // create our link using our new field class
                    $field_types[$name] = $type['class'];
                }
            }

            // send it back
            return $field_types;
        }
codeaken commented 9 years ago

You are right. The output of get_declared_classes() is not consistent between vanilla PHP and HHVM

http://3v4l.org/1p3sY

EdHurtig commented 9 years ago

Yup, I am opening a PR for this because I wrote a fix for this a while ago and was harshly reminded of it when I updated the plugin by mistake