Error must take Exactly 2 Arguments - PHP/Wordpress/visual

Asked

Viewed 61 times

0

Hello, I’m trying to create a custom component for visualComposer a dropdown, I have the php search.php file that creates the custom component, and I have the Recipe.php file that returns the data to be displayed in the component, the problem is that when I run the page does not show the component nor the data of the Recipe.php file..

By Wordpress DEBUG presents the following message below:

 [03-Feb-2018 02:33:07 UTC] PHP Fatal error:  Method ImmutableValueObject::__set() must take exactly 2 arguments in /var/www/html/wp-content/themes/n2go-2014/visual-composer/elements/Receita.php on line 33

Finally follows the contents of the PHP files mentioned :

Search.php

    <?php
include 'Receita.php'; 

class Pesquisa extends WPBakeryShortCode
{  

}

$atts = Integration::instance()->get_default_shortcode_attrs();
vc_map([
    'name' => __('N2Go Integrations', 'js_composer'),
    'base' => 'n2go_integrations',
    'icon' => 'icon-heart',
    'category' => [__('Content', 'js_composer')],
    'params' => array_map(


        function($key, $default){
            return [
                'type' => 'Dropdown',
                'heading' => ucwords(str_replace('_', ' ', $key)),
                'param_name' => $key,
                'value' => $default,
            ];
        },
        array_keys($att),
        $atts
    ),
    'descrição' => 'alguma descrição',
]);

?>

Recipe.php

    <?php

/**
 * Utility base class that makes it easier to fill in readonly value objects.
 * @internal
 */
abstract class ImmutableValueObject
{
    protected $data = [];

    final public function __construct(array $properties = [])
    {
        $this->data = array_merge($this->data, $properties);
    }

    final public function __get($name)
    {
        if (!array_key_exists($name, $this->data)) {
            throw new RuntimeException(sprintf('Undefined property: %s::%s', __CLASS__, $name));
        }

        return $this->data[$name];
    }

    final public function __set($name)
    {
        throw new RuntimeException(sprintf(
            '%s property: %s::%s',
            array_key_exists($name, $this->data) ? 'Readonly' : 'Undefined',
            __CLASS__,
            $name
        ));
    }
}

/**
 * @internal This is just a stub.
 *
 * @property string $id Unique ID of the integration
 * @property string $name Full name of integration, eg; 'WordPress'
 * @property string $abbreviation Short code of integration, eg; 'MAG' for Magento or 'WP' for WordPress
 * @property string $imageUrl Logo of the integration, usually in SVG format
 * @property string $helpUrl User guide URL - can be empty, in which case disable or hide help link
 * @property string $type A value from: 'CRM', 'CMS' or 'Webshop'
 * @property IntegrationSystem[] $items List of supported integrations (plugins or connectors bound to one system)
 */
class Integration extends ImmutableValueObject {}

/**
 * @internal This is just a stub.
 *
 * @property string $id Unique ID of the integration system
 * @property string $edition Eg; 'v4.2', 'v3 and older' or 'All Versions' - used in combination with integration
 * @property int $position Used for ordering
 * @property IntegrationPlugin[] $plugins List of plugins that support this edition.
 * @property IntegrationConnector[] $connectors List of connectors that support this edition.
 */
class IntegrationSystem extends ImmutableValueObject {}

/**
 * @internal This is just a stub.
 *
 * @property string $id Unique ID of the plugin
 * @property string $version Eg; '4000' or '4.0.0.0' - if it is 4 chars and no dots, then it should be formatted with dots between each char.
 * @property string $url Full URL for download the plugin. This may be a direct download or a page showcasing the plugin in a marketplace.
 */
class IntegrationPlugin extends ImmutableValueObject {}

/**
 * @internal This is just a stub.
 *
 * @property string $id Unique ID of the connector
 * @property string $version Eg; '4000' or '4.0.0.0' - if it is 4 chars and no dots, then it should be formatted with dots between each char.
 */
class IntegrationConnector extends ImmutableValueObject {}

/** @var Integration[] $sampleData */
$sampleData = [
    new Integration([
        'id' => '1',
        'name' => 'Amazon',
        'abbreviation' => 'AM',
        'imageUrl' => '//files-staging.newsletter2go.com/integration/amazon.svg',
        'helpUrl' => 'https://www.newsletter2go.de/features/amazon-newsletter-integration/',
        'type' => 'Webshop',
        'items' => [
            new IntegrationSystem([
                'id' => '1',
                'edition' => 'All Versions',
                'position' => 0,
                'plugins' => [],
                'connectors' => [
                    new IntegrationConnector(['id' => '1', 'version' => '3000']),
                ],
            ])
        ]
    ]),
    new Integration([
        'id' => '2',
        'name' => 'Lightspeed eCom',
        'abbreviation' => 'LS',
        'imageUrl' => '//files-staging.newsletter2go.com/integration/lightspeed.svg',
        'helpUrl' => '',
        'type' => 'Webshop',
        'items' => [
            new IntegrationSystem([
                'id' => '2',
                'edition' => 'All Versions',
                'position' => 0,
                'plugins' => [],
                'connectors' => [
                    new IntegrationConnector(['id' => '2', 'version' => '3000']),
                    new IntegrationConnector(['id' => '3', 'version' => '3001']),
                    new IntegrationConnector(['id' => '4', 'version' => '3002']),
                    new IntegrationConnector(['id' => '5', 'version' => '3003']),
                ],
            ])
        ]
    ]),
    new Integration([
        'id' => '3',
        'name' => 'WordPress',
        'abbreviation' => 'WP',
        'imageUrl' => '//files-staging.newsletter2go.com/integration/wordpress.svg',
        'helpUrl' => 'https://www.newsletter2go.com/help/integration-api/set-up-wordpress-plug-in/',
        'type' => 'CMS',
        'items' => [
            new IntegrationSystem([
                'id' => '2',
                'edition' => 'All Versions',
                'position' => 0,
                'plugins' => [
                    new IntegrationPlugin(['id' => '1', 'version' => '2100', 'url' => 'https://www.newsletter2go.de/plugins/wordpress/wp_v2_1_00.zip']),
                    new IntegrationPlugin(['id' => '2', 'version' => '3000', 'url' => 'https://www.newsletter2go.de/plugins/wordpress/wp_v3_0_00.zip']),
                    new IntegrationPlugin(['id' => '3', 'version' => '3003', 'url' => 'https://www.newsletter2go.de/plugins/wordpress/wp_v3_0_03.zip']),
                    new IntegrationPlugin(['id' => '4', 'version' => '3005', 'url' => 'https://www.newsletter2go.de/plugins/wordpress/wp_v3_0_05.zip']),
                    new IntegrationPlugin(['id' => '5', 'version' => '4006', 'url' => 'https://www.newsletter2go.de/plugins/wordpress/wp_latest.zip']),
                ],
                'connectors' => [
                    new IntegrationConnector(['id' => '6', 'version' => '3000']),
                ],
            ])
        ]
    ]),
];

return $sampleData;
  • The Magic method, __set() You don’t have to take two parameters ? see: http://php.net/manual/en/language.oop5.overloading.php#Object.set, even if you are not going to use it, leave it as __set($name, $value = null)

  • final public function __set($name, $value = null)&#xA; {&#xA; throw new RuntimeException(sprintf('%s property: %s::%s',array_key_exists($name, $this->data) ? 'Readonly' : 'Undefined',__CLASS__,$name));&#xA; }&#xA;} , I tried to change the set arguments, but the error still persists.

  • which version of PHP Voce is using ?

  • PHP 5.6.33, Via Docker .

  • I’m using 7.0.27-0+deb9u1 and here it was right, I just changed the return at the end of the page by var_dump()

  • I will try to upgrade to this version of PHP, let’s see if it solves, strange that already includes the two arguments in __set() and still the error persists .

  • I also did it to work, before it wasn’t working. I’m talking about __set() without two parameters

  • I updated wordpress, but the error continues, I do not know how to update PHP by Docker .

  • Complicated, because I have no idea either :)

  • now I am closer to the solution, with your tip I managed to resolve this error of the post, now the following error is happening : [04-Feb-2018 20:39:12 UTC] PHP Fatal error: Cannot access property Integration::$data in /var/www/html/wp-content/themes/n2go-2014/visual-composer/elements/Pesquisa.php on line 9, can help me with this error ? I changed the following line from the previous code : $atts = Integration::$data->get_default_shortcode_attrs();

  • She’s like protected, if you want to access it so you have to leave it as public. Just change the protected for public

  • https://i.imgur.com/vAfug0Z.png

  • Thanks so much for the help, I will close the topic and create another because now the error presented is another but it is related to these classes .

  • as I close the topic ?

  • unfortunately I could not finish the topic nor find the upvote option .

  • You only get 15 reputation points

Show 11 more comments
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.