Trying to get property of non-object in codeigniter class my_exception - codeigniter

I encounter this error in my CI code
A PHP Error was encountered
Severity: Notice
Message: Trying to get property of non-object
Filename: core/MY_Exceptions.php
Line Number: 11
and this is my CI code
class MY_Exceptions extends CI_Exceptions {
function __construct() {
parent::__construct();
$CI =& get_instance();
var_dump($CI);
}
I don't know why this happen, wherein in the documentation it says the same syntax.
Is there anyone here know about this?
What to do about it?

New to me, but I found this and this might help
https://forum.codeigniter.com/thread-67859-post-342719.html
When extending the CI Exception class, there is no way to get the
instance with "get_instance()" because as what i've seen, CI isn't
loading the core before the Exception controller. I need some basic
functions to generate my 404 error pages, so this behavious is
completely useless for me as it only handles static output.

Related

Laravel - Non-static method should not be called statically

I have recently started using laravel for work and I boumped into many issues I cannot stil solve.
I have looked over many many topics and already anwered questions but none of those have helped me with my issue
So, I get this error trying to do 'php artisan serve'
"Non-static method Illuminate\Cache\RateLimiter::for() should not be called statically"
So I went up looking at the code, this is the RateLimiter.php code that gives me the error
protected function configureRateLimiting()
{
RateLimiter::for('api', function (Request $request) {
return Limit::perMinute(60)->by(optional($request->user())->id ?: $request->ip());
});
}
the error is at the 2nd line of this code, in the RateLimiter:: etc
I get those errors in the CMD
app/Providers/RouteServiceProvider.php:59
Illuminate\Foundation\Bootstrap\HandleExceptions::handleError("Non-static method Illuminate\Cache\RateLimiter::for() should not be called statically", "myPathToTheProject/app/Providers/RouteServiceProvider.php", [])
app/Providers/RouteServiceProvider.php:38
App\Providers\RouteServiceProvider::configureRateLimiting()
the function is called like this
$this->configureRateLimiting();
hoping you can help me, I will give more infos if are needed
I found out the problem. You need to import the facade, and when you auto-import, it tends to get the wrong package.
Look at the imports. If you find:
use Illuminate\Cache\RateLimiter;
You should replace with
use Illuminate\Support\Facades\RateLimiter;
Worked for me!

Laravel 5.8 Call to undefined method Illuminate\Events\Dispatcher::fire()

I get this error on user registration. I have searched for this problem a lot and still couldn't solve the problem on my side. In laravel 5.8 upgrade, it's written that function fire() is changed to dispatch(), but I can't find any fire() function in any file of my app, so I can see what's happening.
Would appreciate any help. Thanks.
From: https://laravel.com/docs/5.8/events#dispatching-events
Instead of:
Event::fire(new \App\Events\NewUserSignup($new_user));
Do instead:
event(new \App\Events\NewUserSignup($new_user));
The fire method (which was deprecated in Laravel 5.4) of the Illuminate\Events\Dispatcher class has been removed(https://github.com/laravel/framework/pull/26392). You should use the dispatch method instead.
Instead of:
Event::dispatch('customer.created', $customer);
Do this:
Event::dispatch('customer.created', $customer);
OR:
event('customer.created', $customer);

Migrating to Laravel 5, route:cache throwing exception

Moving from Laravel 4.2 to 5.0
We have about ~200 routes in our API, most of them were Closures. So I've spent the better part of the last couple days converting them all to controller routes. Everything is back to being stable, but when I try to run php artisan route:cache it throws an exception
[Exception]
Serialization of 'Closure' is not allowed
I did a ctrl+f for function, and the only ones left in the routes file are the two Route::group entries (which, yes, are closures...but surely only routes count...).
Any guidance? After the tediousness of the last two days, this error is...not what I wanted to see.
EDIT: Full stacktrace
Route cache cleared!
[Exception]
Serialization of 'Closure' is not allowed
Exception trace:
() at C:\Users\cjtho_000\Desktop\ecapi_l5\vendor\laravel\framework\src\Illuminate\Foundation\Console\RouteCacheCommand.php:95
serialize() at C:\Users\cjtho_000\Desktop\ecapi_l5\vendor\laravel\framework\src\Illuminate\Foundation\Console\RouteCacheCommand.php:95
Illuminate\Foundation\Console\RouteCacheCommand->buildRouteCacheFile() at C:\Users\cjtho_000\Desktop\ecapi_l5\vendor\laravel\framework\src\Illuminate\Foundation\Console\RouteCacheCommand.php:65
Illuminate\Foundation\Console\RouteCacheCommand->fire() at n/a:n/a
call_user_func_array() at C:\Users\cjtho_000\Desktop\ecapi_l5\vendor\laravel\framework\src\Illuminate\Container\Container.php:523
Illuminate\Container\Container->call() at C:\Users\cjtho_000\Desktop\ecapi_l5\vendor\laravel\framework\src\Illuminate\Console\Command.php:115
Illuminate\Console\Command->execute() at C:\Users\cjtho_000\Desktop\ecapi_l5\vendor\symfony\console\Symfony\Component\Console\Command\Command.php:257
Symfony\Component\Console\Command\Command->run() at C:\Users\cjtho_000\Desktop\ecapi_l5\vendor\laravel\framework\src\Illuminate\Console\Command.php:101
Illuminate\Console\Command->run() at C:\Users\cjtho_000\Desktop\ecapi_l5\vendor\symfony\console\Symfony\Component\Console\Application.php:874
Symfony\Component\Console\Application->doRunCommand() at C:\Users\cjtho_000\Desktop\ecapi_l5\vendor\symfony\console\Symfony\Component\Console\Application.php:195
Symfony\Component\Console\Application->doRun() at C:\Users\cjtho_000\Desktop\ecapi_l5\vendor\symfony\console\Symfony\Component\Console\Application.php:126
Symfony\Component\Console\Application->run() at C:\Users\cjtho_000\Desktop\ecapi_l5\vendor\laravel\framework\src\Illuminate\Foundation\Console\Kernel.php:94
Illuminate\Foundation\Console\Kernel->handle() at C:\Users\cjtho_000\Desktop\ecapi_l5\artisan:36
EDIT 2: removed the route groups to test, still throws the exception
Turns out, the entirely unhelpful error message was trying to tell me that I had a duplicate route (copy paste error, I had two get routes matching the same uri).
Removing the duplicate fixed the issue.
Per your stack trace,
vendor\laravel\framework\src\Illuminate\Foundation\Console\RouteCacheCommand.php:95
serialize() at vendor\laravel\framework\src\Illuminate\Foundation\Console\RouteCacheCommand.php:95
Laravel is trying to serialize the routes collection on line 95 of RouteCacheCommand.php.
The error you're getting
Serialization of 'Closure' is not allowed
looks like its PHP's standard "someone tried to serialize an anonymous function" exception message (vs. it might be a custom Laravel exception).
All this means something is adding an anonymous function (i.e. "closure") to your route collection. If you're 100% sure you've removed them all from routes.php, my guess would be the route's in third party code somewhere.
It's best not to guess. Try some debugging code that's something like the following
//un-tested pseudo debugging code
//get the application's routes, using the same
//technique as the route:cache command
$app = require /path/to/your/laravel/bootstrap/app.php';
$app->make('Illuminate\Contracts\Console\Kernel')->bootstrap();
$routes = $app['router']->getRoutes();
//go through each route
foreach($routes as $route)
{
//if the route is a closure
if(is_object($route) && ($route instanceof Closure))
{
//use reflection to find out which file the closure is defined in
$r = new ReflectionFunction($route);
var_dump($route->getFileName ());
}
}
This will let you figure out where the closure that's causing your problems is defined, which should be enough to point to the problem.

Magento Mage class causes server error 500 in own php script

I got a few problems with the Mage Class, when we try to call any static method, e. g. in my case:
Mage::getModel('catalog/product')->load($productId);
It always causes an error 500. It´s been used in an own php design file.
Also, this post didn´t resolve the problem: Magento 1.7 - getModel in script outside web application fails
I searched a lot in the internet and found out, that
Mage::getModel();
is a factory method, so I actually don´t need to call
Mage::getConfig()->init();
Mage::getConfig()->loadModules();
Help me, please!
Edit: I solved the error with this code:
Mage::app()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID);
$category = Mage::getModel('catalog/category')->load($categoryId);
$prodCollection = Mage::getResourceModel('catalog/product_collection')->addCategoryFilter($category);
$prodCollection->addAttributeToSelect('attribute_name');
The main problem was, that this line was missing:
Mage::app()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID);
The error might be caused by this:
Mage::getModel()->('catalog/product')->load($productId);
This is wrong. First of all getModel expects at least a parameter. Second, there is no method name here ->('catalog/product'). Your code should be:
Mage::getModel('catalog/product')->load($productId);
Also make sure that Mage.php is included in your script otherwise the class is not found.

when might magento Mage::getModel('customer/form'); fail?

I have the following two lines of code in within a controller class.
$customerForm = Mage::getModel('customer/form');
$customerForm->setFormCode('customer_account_create')
->setEntity($customer);
I am getting "Fatal error: Call to a member function setFormCode() on a non-object in ..."
on the second of those two lines.
what might cause the first line to return a "non-object" ? (I guess it fails and returns a null but why would this happen ?)
I am not sure if this is relevant but this is happening in a site that uses the Enterprise version of magento (Magento ver. 1.8.0.0).
Look into your exeption.log, you should find some ideas there. It might happen if Mage_Customer module is disabled, you have rewrite for 'customer/form' model, or even file with Mage_Customer_Model_Form class is missing.

Resources