yii2 project running errors - php

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

Related

Parse error - Wordpress

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.

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

PHPUnit & Group Use statements

I am using PHPUnit to test my project running in PHP 7.0.2, but it seems to have issues with the group use statement. For example, this is an example file using a group use statement:
test.php
<?php
namespace MyFramework;
use \OtherFramework\{
AwesomeClass,
OtherAwesomeClass
};
// do ALL the things
When I run
php test.php
it works fine as expected. Now I was using PHPUnit 4.8.21, but when I tried
phpunit test.php
I got the error
Parse error: parse error, expecting `"identifier (T_STRING)"' in test.php on line 4
Mind you, I am using other PHP 7 features such as the null coalesce operator (??) just fine in other tests, so I know that PHPUnit is running PHP 7. Next I tried upgrading to the preferred stable version (5.1.4) and got this response:
This version of PHPUnit requires PHP 5.6; using the latest version of PHP is highly recommended.
And even my old tests without a group use statement won't run.
How can I run PHPUnit with PHP 7 and get the group use statements to work?

Fatal error: Class 'PHPExcel_Shared_String' not found

I have used PHPExcel for my codeigniter app and it is working perfectly in localhost, but when I host this to server, I am getting following error :
Fatal error: Class 'PHPExcel_Shared_String' not found in \xx\xx\xx
third_party\PHPExcel\Autoloader.php on line 36
There was a change introduced to the autoloader in the latest version of PHPExcel that appears to have broken backward compatibility with versions of PHP < 5.3.0
If you edit the Classes/PHPExcel/Autoloader.php file and change line 58, which should read
return spl_autoload_register(array('PHPExcel_Autoloader', 'Load'), true, true);
to
return spl_autoload_register(array('PHPExcel_Autoloader', 'Load'));
I've already made a change to the develop branch on github to test for the PHP version and execute the appropriate line
While this was not deliberate, please note that we really are trying to get users to upgrade to at least version 5.3.0 of PHP, because we can't address any of the memory/performance issues that users working with large spreadsheets complain about until we can use some of the new features available in more recent versions of PHP. Version 5.2 of PHP is no longer supported, and even version 5.3 is end-of-life and will be unsupported before the end of this year
struggled with this issue for a long time under Linux and PHP 5.4x. In the end, in addition to the fix above, I resorted to changing the code on line 73 of the Autoloader file which sets the $pClassFilePath variable from relative (using PHPEXCEL_ROOT) to absolute following the machines file tree. This might only be a hack, but it saved my sanity after several days of trying. Hope this helps someone. Cheers
I had this issue too and i solved it by changing permissions on "Shared" directory to 655.
I Hope it helps
If your server is on Linux, it can be permission problem... Just add all permissions for PHPExcel Folder in you Vendor (on server side) and all subfolders for it. I have same problem and i have solved it by this way...
What worked for me was changing PHPExcel/Autoloader.php line 81 from
if ((file_exists($pClassFilePath) === FALSE) || (is_readable($pClassFilePath) === FALSE)) {
to
if ((stream_resolve_include_path($pClassFilePath) === FALSE)) {
I prefer this approach because it didn't require me to modify file permissions and it should work in PHP 5.3.2 and later.

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