2

While installing custom module at server i'm getting this error at frontend. My php version at server is 5.6. But same module at my localhost with php 7.0 version is working fine. I'm not able to understand this why this error showing. The error line code is below:

array(
    $this->_productVisibility::VISIBILITY_BOTH,
    $this->_productVisibility::VISIBILITY_IN_CATALOG
);

Any single help would be appreciated. Thanks in advance.

  • (1) The error message should specify a particular file and line. Include that line in your question, so we can actually help. (2) If this is a third-party extension, you should contact the creator. – Ryan Hoerr Dec 19 '16 at 14:36
  • Without the full error message and at least the line of code that causes it, this is guesswork. But a parse error suggests that this custom module probably requires PHP 7. – Fabian Schmengler Dec 19 '16 at 14:37
  • @fschmengler, In your comment you mentioned PHP 7. Can you explain little more about why php 7 need?. – Pinku Dec 19 '16 at 17:24
8

The code in your module is not PHP 5.6 compatible. Consider the following program.

#File: test.php
<?php
class A
{
    public function foo(){
        $foo = array( 
            $this->_productVisibility::VISIBILITY_BOTH, 
            $this->_productVisibility::VISIBILITY_IN_CATALOG
        );
    }
}

If you run this through PHP's standard lint scanner (in PHP 5.6)

$ php -l test.php

You'll end up with the following error

Parse error: parse error, expecting `')'' in test.php on line 6 Errors parsing test.php

The problem is trying to access a class constant on an instance variable.

$this->_productVisibility::VISIBILITY_BOTH

This is invalid syntax in PHP 5.6. Whomever wrote this code did not write it with PH 5.6 support in mind.

The right thing to do here? Use a server with PHP 7. PHP 5.6 goes out of active support at the end of this year (2016), and while it has 2 years left os security patch support, Magento runs much better with a PHP 7 enviornment.

If that's not possible, you'll need to fork the extension, and rewrite all the code in a PHP 5.6 compatible way, and reapply your changes whenever the extension updates.

1

Hello Guys i got solution of my own question. just replace below code

array( $this->_productVisibility::VISIBILITY_BOTH, $this->_productVisibility::VISIBILITY_IN_CATALOG );

to

$this->_productVisibility->getVisibleInSiteIds());

Now this code is compatible with PHP 5.6 as well as 7

Thanks for @Alan Storm for guiding me

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.