how to solve Illuminate/database syntax error on ForwardsCalls trait - php

This is just happening today when I'm updating my website. Actually I didn't even touch this file but for some reason it shows error and my website can't be loaded.
Here is the problem
try {
return $object->{$method}(...$parameters);
} catch (Error | BadMethodCallException $e) { // "|" << this is the error
$pattern = '~^Call to undefined method (?P<class>[^:]+)::(?P<method>[^\(]+)\(\)$~';
if (! preg_match($pattern, $e->getMessage(), $matches)) {
throw $e;
}
if ($matches['class'] != get_class($object) ||
$matches['method'] != $method) {
throw $e;
}
static::throwBadMethodCallException($method);
}
I have tried to search about catch one of two exception but none. How can I solve this. I don't even know about trait. Thanks before

From exceptions documentation
In PHP 7.1 and later, a catch block may specify multiple exceptions
using the pipe (|) character.
You're developing on a machine with newer version of PHP but deploying on an older version. You really should consider using exact same version of PHP on both machines to avoid backward compatibility issues.
To solve your problem, you can choose a newer version of PHP if your hosting company offers such a feature, or downgrade the library you're using to a version compatible to the PHP version of your host. I don't recommend the second method, downgrading a package to deal with outdated dependencies is not a good idea.

Related

Laravel - Exception thrown at Guzzle function when running seeder

Running php artisan db:seed throws the following error: GuzzleHttp\Exception\InvalidArgumentException : IDN conversion failed (errors: IDNA_ERROR_EMPTY_LABEL) at vendor/guzzlehttp/guzzle/src/functions.php:384
Never seen this error before and it doesn't appear to be an issue with my seeder syntax.
The partial exception trace is:
1 GuzzleHttp\_idn_uri_convert()
/home/vagrant/code/companion-2.0/vendor/guzzlehttp/guzzle/src/Client.php:220
2 GuzzleHttp\Client::buildUri()
/home/vagrant/code/companion-2.0/vendor/guzzlehttp/guzzle/src/Client.php:113
I'm running commands within a vagrant/homestead environment. Could this be a version incompatibility?
This is an issue with guzzle 6.5.0. See more info here: https://github.com/guzzle/guzzle/issues/2448
Solution: downgrade to version 6.4.1.
Please, try to upgrade to the latest stable version (6.5.2 at the moment). We did our best to consider all possible installation details, so you should not have this error anymore.
If the error still occurs, please report it as a bug here: https://github.com/guzzle/guzzle/issues.
Right now, the best solution is update, the lastest version works fine

Process Component Symfony failed to execute behat command

I'm currently working on a package of Laravel that will launch behats tests directly from our browser. this is a personal project.
I use the Process Component Symfony to execute various commands. However, it can not execute the command Behat and returns me this error:
vendor / bin / Behat "failed.
Exit Code: 255 (Unknown error) Working directory: / Applications / MAMP / htdocs / Package / public
Output: ================ Parse error: parse error, expecting '&' 'or "variable (T_VARIABLE)' 'in / Applications / MAMP / htdocs / Package / vendor /laravel/framework/src/Illuminate/Foundation/helpers.php on line 475
Error Output: ================
In short, he refused to execute all commands Behat. Here the use of the command in the controller of my package.
<? Php
namespace Nkweb\BehatWeb\Http\Controllers;
use App\Http\Controllers\Controller;
use Symfony\Component\Process\Exception\ProcessFailedException;
use Symfony\Component\Process\Process;
class BehatWebController extends Controller
{
    
    public function launchBehat()
    {
        
        $command = base_path('vendor/bin/Behat');
        $process = new Process($command);
        try {
            $process->mustRun();
            $outputs = explode("\n", $process->getOutput());
        } Catch (ProcessFailedException $e) {
            return $e->getMessage();
        }
        return view('behatweb::content.init', ['outputs' => $outputs]);
    }
}
I searched google and returned in every way but I could not find anything about it. I really need your help :(
I'm not a Laravel user but I'll give it a shot. I'll walk through my process so hopefully it will help you debug similar issues in the future. I'm assuming you're using the latest Laravel but would be helpful if you could state which version you're running.
Looking at the error, we have a nice place to start. Line 475 in laravel/framework/src/Illuminate/Foundation/helpers.php. Which is the first line below:
function event(...$args)
{
return app('events')->fire(...$args);
}
And we are expecting a variable or & (pass by reference) according to the error, so we can assume it is talking about the parameter in the event function. Now we can see the parameter is preceded by ... this is a hard one to Google but you might get better results searching for the "splat" operator (note, different languages may have alternative names).
This was introduced in PHP 5.6, which leads me to believe you are running an earlier version which is not supported. I'd suggest upgrading to PHP 5.6 or above and seeing if that fixes your issue. If it doesn't, please post the version of PHP you're using.

Including Paragonie Halite in project doesn't find variables and functions

I've installed libsodium on Windows for PHP 7 and I'm developing my project with PHPStorm. I've also installed Halite from Paragonie which couldn't even be installable if the libsodium extension were not installed correctly. Also the IDE finds the used functions and when clicking on the variables and so on it opens up the fitting files of libsodium.
But unfortunately in my setup I get the following error:
Uncaught Error: Undefined constant 'Sodium\CRYPTO_PWHASH_OPSLIMIT_INTERACTIVE' in C:\Server\nginx-1.11.1\html\mywebsite\vendor\paragonie\halite\src\KeyFactory.php:344
My index.php file looks like the following:
<?php
require_once 'vendor/autoload.php';
spl_autoload_register(function ($class) {
require_once $class . '.php';
});
$router = new AltoRouter();
$router->setBasePath('/' . basename(__DIR__));
require_once 'config/routes.php';
$match = $router->match();
$GLOBALS['db'] = new \config\database(true, null);
try
{
if ($match) {
$routeController = new Modules\Core\RouteController($match);
echo $routeController->bootstrap();
}
}
catch (Exception $ex)
{
//#todo log every Exception
}
I'm also submitting my form with Jquery which leads successfully to the execution of the following function (which doesn't find the libsodium functions/variables):
public function hash($password)
{
$this->setEncryptionKey();
return Password::hash(
$password, // string
$this->encryption_key // \ParagonIE\Halite\Symmetric\EncryptionKey
);
}
public function check($stored_hash, $password)
{
try {
if (Password::verify(
$password, // string
$stored_hash,
$this->encryption_key
)) {
return true;
}
} catch (\ParagonIE\Halite\Alerts\InvalidMessage $ex) {
// Handle an invalid message here. This usually means tampered ciphertext.
throw new \Exception($ex);
}
}
I've installed the php_libsodium.dll in the extension directory and put the libsodium.dll in in the directory of the php server. Just for trying out i put it later also in system32 directory and in Syswow64 directory - both didn't change anything.
I just installed the halite library from paragonie with composer but using it is unfortunately harder than I thought. I also tried to use the libsodium extension without Halite but that lead to similar errors that the needed classes, constants and functions and so on were not found.
I've also tried to change my autoloader, but the strange thing anyway is that the IDE finds everything without problems but executing the script in the browser just don't.
In order to use Halite 2.x, you need to have:
Libsodium 1.0.9+ (preferably 1.0.10 if you have trouble compiling .9)
PECL Libsodium 1.0.3+ (preferably 1.0.6) compiled against libsodium 1.0.9+.
The easy way to verify that this is set up is:
<?php
use \ParagonIE\Halite\Halite;
var_dump(Halite::isLibsodiumSetupCorrectly());
If you want a little more specific information on what's failing, just run this instead:
<?php
use \ParagonIE\Halite\Halite;
// TRUE enables verbose output:
Halite::isLibsodiumSetupCorrectly(true);
Most likely, you'll need to uninstall/reinstall the PHP extension compiled against a newer version of the shared library.
There's an RFC under discussion for PHP 7.1 right now that will make this painless in the future, if accepted. The RFC passed, years later; libsodium will be in PHP 7.2.

Why does geoip throw an exception?

Why this code:
geoip_country_code_by_name('unknown');
generate ErrorException, when must return false ?
This is a bug in GeoIP package and is not fixed in any release (<= 1.0.8). It's fixed in the trunk however (see this revision). You can solve this by compiling the source from the latest trunk.
Edited: thanks to Wrikken for pointing out how Laravel handles errors.
With GeoIP <= 1.0.8 geoip_country_code_by_name will trigger an error (E_NOTICE) whenever the name cannot be found. Laravel will always set error_reporting to -1 and handle all errors (even notices) and translate them into ErrorExceptions. Normally one can catch ErrorExceptions using a try-catch block, but in this case it is not possible because Laravel never throws the exception, it just translate it for displaying and logging purposes.
It is possible to ignore the error with the #-operator. It's a bit bad to do so since it will ignore all errors that the function might throw. In this case however, the only other error geoip_country_code_by_name can trigger is warning when the database can't be reached. Therefore you can safely ignore the error if you make sure the database is available: (Code not tested)
if (geoip_db_avail(GEOIP_COUNTRY_EDITION))
{
#geoip_country_code_by_name('unknown');
}
else
{
// Throw exception or handle the error
throw new Exception(
"Required database not available at " .
geoip_db_filename(GEOIP_COUNTRY_EDITION)
);
}
Edit:
Laravel now throws the ErrorException so that one can catch it using a try-catch block. At the time of writing, this change is not yet in any released tag. But a catching errors will probably work with Laravel/Framework >= 4.0.8.
In 1.1.0 module version bug fixed https://pecl.php.net/package-changelog.php?package=geoip&release=1.1.0

why is Eclipse objecting to `static::$var`?

I have the following static function in a PHP class:
static function __callStatic($method,$args){
$called=NULL;
if(empty(static::$collection)) static::slurp();
if(method_exists(static::$objtype,$method)){
foreach(static::$collection as $obj){
$called[]= call_user_func_array(array($obj, $method), $args);
}
} else if (property_exists(static::$objtype,$method)){ //$method isn't a method, it's a property
foreach(static::$collection as $obj){
$called[]= $obj->$method;
}
} else if($method=='collection'){
$called=static::$collection;
} else {
throw new ZException("$method does not exist");
}
return $called;
}
The static variables are all defined but possibly not set. The code appears to do what I want it to and throws no errors of any level. But yet my new installation of Eclipse (Helios) PDT has marked every instance of static::$var as an 'unexpected static' error. If I replace static::$var with self::$var the Eclipse error goes away- but then the code doesn't work.
How do I convince Eclipse that these are not errors?
Eclipse for PHP Developers
Version: Helios Service Release 1
Build id: 20100917-0705
on 64 bit CentOS
Late Static Binding was introduced with PHP 5.3. Check Window > Preferences > PHP > Executables and Interpreter to make sure Eclipse is using PHP 5.3.
The use of static:: was introduced in PHP 5.3.
My guess would be that Eclipse is parsing according to PHP 5.2 rules. Either that, or its an oversight when they implemented the 5.3 rules in Eclipse.
Either way, you may be able to upgrade or patch Eclipse with a new rule set to get it to parse 5.3 syntax correctly.

Categories