Parse error - Wordpress - php

I bought Aurora wordpress theme from Themeforest.
When I'm trying to install it, I have parse error: unexpected ':' in functions.php file on line 361.
Functions.php line 361
$customizer_template_setting = get_theme_mod('aurora_post_layout') ?: 'default';
How can I fix it?

It's the shortened ternary syntax, that is only available in PHP 5.3 and newer.
You should check your PHP version (and in case update it, recommended!).
That syntax is equivalent to:
$customizer_template_setting = get_theme_mod('aurora_post_layout') ? get_theme_mod('aurora_post_layout') : 'default';
The extreme solution if you cannot update your PHP version would be to replace that line.

Related

When i am trying to export excel file in php 7 same code is working in php5

When i am trying to export excel file in php 7 same code is working in php5
$worksheet =& new writeexcel_worksheet($name, $index, $this->_activesheet,
$this->_firstsheet,
$this->_url_format, $this->_parser,
$this->_tempdir);
Parse error: syntax error, unexpected 'new' (T_NEW) in C:\xampp\htdocs\developer\wp-content\plugins\liveunited-payments\php_writeexcel\class.writeexcel_workbook.inc.php on line 190
php7 is not fully compatible with php5, in most cases you have to refactor some code.
First, try to remove "&" near "new"
$worksheet =new writeexcel_worksheet($name, $index, $this->_activesheet,
$this->_firstsheet,
$this->_url_format, $this->_parser,
$this->_tempdir);
I noticed that error causes in some external library. The best way is update that vendor to version with php7 support

How to use TOTP / HOTP library in PHP

I tried to implement TOTP PHP library as another authentication for my login form. I downloaded and followed installation instruction from github as folowing code:
<?php
include('src/Factory.php');
include('src/HOTP.php');
include('src/HOTPInterface.php');
include('src/OTP.php');
include('src/OTPInterface.php');
include('src/ParameterTrait.php');
include('src/TOTP.php');
include('src/TOTPInterface.php');
use OTPHP\TOTP;
$otp = TOTP::create();
echo 'The current OTP is: '.$otp->now();
?>
Yet, I ended up with error message Warning: Unsupported declare 'strict_types' in C:\wamp64\www\otp\src\HOTP.php on line 3 and Parse error: syntax error, unexpected '?', expecting variable (T_VARIABLE) in C:\wamp64\www\otp\src\HOTP.php on line 28.
I could not figure out why it was that. Very much appreciate for your help. Thanks.
Install lower version of package like ~8.0, which works with PHP 5.5
https://github.com/Spomky-Labs/otphp/blob/v8.3.2/composer.json#L19
add this in your composer.json
"require": {
"spomky-labs/otphp": "~8.3"
}
Or use this link to download it as ZIP and add it to your project manually
https://github.com/Spomky-Labs/otphp/archive/v8.3.2.zip
Better is to use composer, because you have auto autoloader. :) That way there is no need to manually require files.
try the multiOTP class, which is PHP 5.x compatible
https://github.com/multiOTP/multiotp

yii2 project running errors

I am installed yii2 advanced template using composer all are working fine.
System have php7.1.5. Whenever i copy advanced folder in another system it throw syntax error in TestCase.php like below
Parse error: syntax error, unexpected '?' in \advanced\vendor\phpunit\phpunit\src\Framework\TestCase.php on line 822
line 822 is $configurationFilePath = $GLOBALS['__PHPUNIT_CONFIGURATION_FILE'] ?? '';
That another system have php5.6.8
So, i am directly install yii2 advanced in that system and it is working fine.
I am check TestCase.php the file have lot of differences and the particular line also changed like below
$configurationFilePath = (isset($GLOBALS['__PHPUNIT_CONFIGURATION_FILE']) ? $GLOBALS['__PHPUNIT_CONFIGURATION_FILE'] : '');
So i want to know what is going here.My question is not clear please let me know.Thanks in advance
PHP operator ?? is available since PHP7, so u can't expect, that code from PHP7 will work on server with PHP5.
PHP 7 - Null coalescing operator

Syntax error with session function on php5.3

The following function works on php 5.6 but gives error on php 5.3 which is the version of the cpanel im using. im unable to update the cpanel php version so i need to find a workaround..
$url =isset($_SESSION['url']) ? $_SESSION['url'] : [];
the error is:
Parse error: syntax error, unexpected '[' in /home/mydomain/public_html/mypage.php on line 7
any workaround is appreciated, thanks in advance.
Use array() instead of []. Yeah, it's PHP, not JavaScript.

Laravel 4 syntax error out-of-the-box

I just installed Laravel 4 (Illuminate) and as I opened the index.php file in a browser, I was met with this error:
Parse error: syntax error, unexpected 'yield' (T_YIELD), expecting identifier (T_STRING) in /www/Laravel4/vendor/illuminate/view/src/Illuminate/View/Environment.php on line 339
I have fixed the permissions for the meta folder, and installed all the dependencies through Composer. I am running PHP version 5.5.0alpha2 on OSX 10.8.2.
That's because yield became a language construct in PHP 5.5 (used in Generators) - but someone decided that it's a good idea to use this short word to name a function:
public function yield($section)
{
return isset($this->sections[$section]) ? $this->sections[$section] : '';
}
Downgrade to PHP 5.4 (after all, it's the current mainstream version, 5.5 is not even in beta yet) and it should work fine.

Categories