Got error when running Kohana DB migration - php

I am using Kohana php framework, when I try to run minion, I got this exception error:
PHP Fatal error: Call to undefined function __() in /system/classes/Kohana/Kohana/Exception.php on line 53
PHP Fatal error: Call to undefined function __() in /system/views/kohana/error.php on line 64
This is the code in Exception.php:
public function __construct($message = "", array $variables = NULL, $code = 0, Exception $previous = NULL)
{
// Set the message
$message = __($message, $variables);
// Pass the message and integer code to the parent
parent::__construct($message, (int) $code, $previous);
// Save the unmodified code
// #link http://bugs.php.net/39615
$this->code = $code;
}
This is the code in error.php
{<?php echo __('PHP internal call') ?>}

Related

Non-static method should not be called statically in Kohana 2.3.4

i've moved my Kohana 2.3.4 installation to a new hosting with php7 (probably that's a root of the issue) and now i am getting the following error:
Uncaught PHP Error: Non-static method AdminHook::menu_tree() should not be called statically in file system/core/Event.php on line 209
Here's my Event.php around line 209 (call_user_func($callback); is at line 209):
public static function run($name, & $data = NULL)
{
if ( ! empty(self::$events[$name]))
{
// So callbacks can access Event::$data
self::$data =& $data;
$callbacks = self::get($name);
foreach ($callbacks as $callback)
{
call_user_func($callback); // LINE 209
}
// Do this to prevent data from getting 'stuck'
$clear_data = '';
self::$data =& $clear_data;
}
// The event has been run!
self::$has_run[$name] = $name;
}
And here's the AdminHook class:
class AdminHook {
public function menu_tree(){
$session = Session::instance();
if(isset($_GET['_ml']) AND $_GET['_ml'] == 1) {
$session->set('menuLink', 'http://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']);
//url::redirect(url::current());
}
global $menuLink;
$menuLink = $session->get('menuLink');
}
}
If i set menu_tree function to static, i get the following error:
Uncaught PHP Error: Declaration of Menu_Model::validate(array &$array, $save = false) should be compatible with ORM_Core::validate(Validation $array, $save = false) in file application/models/menu.php on line 18
I've been trying to find a solution for the next couple of days, but can't seem to find one. Any help is highly appreciated!
Errors are not related to each other. By simply setting that method as static, php goes to showing the next error.
You have bad Menu_Model declaration. It mut be compatible with ORM_Core::validate
Menu_Model::validate(/*bad: array & */ Validation $array, $save = false)

How to reference a Class Method using an array variable in PHP7?

I've moved from PHP5 to PHP7.
The following code no longer works.
<?php
class sandbox {
function doit() {
$method = array('name' => 'testresponse');
return $this->$method['name']();
}
function testresponse(){
return "Hi!";
}
}
$h = new sandbox();
echo "Hello, " . $h->doit();
I'm wondering what is the new syntax for this?
Here are the PHP errors I'm getting
A PHP Error was encountered Severity: Notice
Severity: Notice
Message: Array to string conversion
Filename: front/sandbox.php
Line Number: 20
And
Fatal error: Uncaught Error: Function name must be a string in /var/www/application/controller/sandbox.php:20 Stack trace: #0
Change this
return $this->$method['name']();
to this
return $this->{$method['name']}();

Lumen 5.6 Error handling (throws exception twice)

This is my code to handle any error:
App\Exceptions\Handler::class
public function render($request, Exception $e)
{
$fe = \Symfony\Component\Debug\Exception\FlattenException::create($e);
$statusCode = $fe->getStatusCode();
$code = $fe->getCode();
$message = $fe->getMessage();
$errorObj = new \App\LOHDomain\Entities\Error($code, $message);
return response()->json(['data' => null, 'error' => $errorObj], $statusCode);
}
when I parse a fake WSDL URL to the SoapClient it throws two exceptions
{"data":null,"error":{"code":"0","message":"SOAP-ERROR: Parsing WSDL: Couldn't load from 'asdsd' : failed to load external entity \"asdsd\"\n"}}
{"data":null,"error":{"code":"1","message":"SOAP-ERROR: Parsing WSDL: Couldn't load from 'asdsd' : failed to load external entity \"asdsd\"\n"}}
So the json response became invalid
When commenting these line of codes in the vendor, it throws one exception:
Laravel\Lumen\Concerns\RegistersExceptionHandlers trait
protected function registerErrorHandling()
{
error_reporting(-1);
set_error_handler(function ($level, $message, $file = '', $line = 0) {
if (error_reporting() & $level) {
throw new ErrorException($message, 0, $level, $file, $line);
}
});
set_exception_handler(function ($e) {
$this->handleUncaughtException($e);
});
// register_shutdown_function(function () {
// $this->handleShutdown();
// });
}
So, What is the problem? and how to solve it without editing in the vendor?
The solution is to clear the last error, because it fired twice.
The error exception.
The second is the shutdown function.
So, the solution is:
App\Exceptions\Handler::class
public function render($request, Exception $e)
{
$fe = \Symfony\Component\Debug\Exception\FlattenException::create($e);
$statusCode = $fe->getStatusCode();
$code = $fe->getCode();
$message = $fe->getMessage();
$errorObj = new \App\Domain\Entities\ResponseEntites\Error($code, $message);
/**
* This line of code resolves the issue
*
* To reproduce the issue :
* 1) Comment this following line of code
* 2) Provide a fake WSDL URL to the SoapClient
*
* Recommendation: Remove this line if you aren't using the SoapClient
*/
error_clear_last();
return new \Illuminate\Http\JsonResponse(['data' => null, 'error' => $errorObj], $statusCode);
}
This isn't the best solution (but this is the best solution, that I tried in my case).
If you have a better tested solution please share it.
links:
Fatal exceptions are handled twice
Code change

PHP OOP, Uncaught Error: Call to a member function setAuthor() on string [duplicate]

This question already has answers here:
Reference - What does this error mean in PHP?
(38 answers)
Closed 5 years ago.
I use PHP version 7 and i get always this error, when i creat a news article:
Fatal error: Uncaught Error: Call to a member function setAuthor() on string in D:\xampp\htdocs\entwicklung\tools\adminlogin\lib\mod\news\newsForm.php:14 Stack trace: #0 {main} thrown in D:\xampp\htdocs\entwicklung\tools\adminlogin\lib\mod\news\newsForm.php on line 14
Here i creat my object and would save the article in my database:
if(isset($_POST["publish"]))
{
$news = new News();
$title = $news->setTitle($db, $_POST["ueberschrift"]);
$news = $news->setNews($db, $_POST["artikel"]);
$author = $news->setAuthor($db, $_POST["autor"]); //This is line 14
News::newsArticleCreate($db, $title, $news, $author);
}
This is my setter-method for the author:
function setAuthor($db, $author)
{
if(!empty($author))
{
$author = mysqli_real_escape_string($db, $author);
return $this->author = trim($author);
}
else
{
return false;
}
}
What is my mistake?
Fatal error: Uncaught Error: Call to a member function setAuthor() on
string
The error says that you are trying to call setAuthor on a string ( $news ) rather than on an object of News Class.
If you replace the following line:
$news = $news->setNews($db, $_POST["artikel"]);
with
$news->setNews($db, $_POST["artikel"]);
It should work fine.

PHP UndefinedFunctionException in simply OR comparison

I am working on a custom web shop project. Currently I am experiencing a strange error when using one of my classes:
namespace Services\MyServices;
class MyAppService {
protected function someMethod($transfer_id) {
...
$hash1 = sha1($someValue1);
$hash2 = sha1($someValue2);
$hash3 = sha1($someValue3);
// The following code is in line 144
$checkHash = (($hash1 == $transfer_id) || ($hash2 == $transfer_id) || ($hash3 == $transfer_id));
...
}
}
Fatal Error: Call to undefined function Services\MyAppService\ ()
Uncaught PHP Exception UndefinedFunctionException: "Attempted to call function " " from namespace "Services\MyAppService"." at /webspace/..../Services/MyAppService/MyAppService.php line 144
So line 144 is just a simple OR comparison, isn't it? What could be the problem here?

Categories