I am working with a code that was not written by me. It is a Laravel 3 application, it is giving me the following error:
PHP Warning: in_array() expects parameter 2 to be array, null given in /Users/use/Documents/project/laravel/error.php on line 87
Can you give me pointers on how to debug it? It is giving error in the file which was included in the framework. Also I using the php's inbuilt server to run the application. Does that cause problems? Any pointers are helpful.
PS: I am on a mac.
After looking at the source code it appears that you are getting the error from this file:
// laravel/error.php
// line 86
if (in_array($code, Config::get('error.ignore')))
{
return static::log($exception);
}
The method appears to be looking for the error.ignore config variable:
// application/config/error.php
// line 16
'ignore' => array(),
Check the application/config/error.php file, make sure that 'ignore' is set to an array. If it already is, then you likely have an error in one of the other config files which is corrupting the array.
Hopefully this helps and shows the steps you can take in tracking down the source of an error.
You can get this also if you're using composer and the required files have not been installed after a fresh checkout of the project. To resolve:
$ composer install
Or similar. To actually get a head on this information I had to throw $exception in the error.php file around line 87, then I saw the reason in the Apache error logs.
Most of this errors is about of parameters definition bug.
for example sometimes coder write
protected $guarded = 'title';
instead of
protected $guarded = ['title'];
That makes the paroblem
Related
For a php project, for some time my tests fail for phpstan and psalm, with unclear error messages.
I tried to debug, to rebuild the commits, but without success. I can't understand or so.
These are the output, the composer.json and the ci.yml.
I can spot these lines. For psalm:
Uncaught Error: Call to undefined method ReflectionUnionType::getName() in phar:///home/runner/work/me-tools/me-tools/vendor/psalm/phar/psalm.phar/src/Psalm/Internal/Codebase/Reflection.php:262
And for phpstan:
PHP Warning: Undefined array key "PHPStan\Rules\Arrays\DuplicateKeysInLiteralArraysRule" in phar:///home/runner/work/me-tools/me-tools/vendor/phpstan/phpstan/phpstan.phar/vendor/nette/utils/src/Utils/Reflection.php on line 180
Warning: Undefined array key "PHPStan\Rules\Arrays\DuplicateKeysInLiteralArraysRule" in phar:///home/runner/work/me-tools/me-tools/vendor/phpstan/phpstan/phpstan.phar/vendor/nette/utils/src/Utils/Reflection.php on line 180
PHP Fatal error: Uncaught TypeError: _HumbugBox5f943a942674\Nette\Utils\Reflection::getUseStatements(): Return value must be of type array, null returned in phar:///home/runner/work/me-tools/me-tools/vendor/phpstan/phpstan/phpstan.phar/vendor/nette/utils/src/Utils/Reflection.php:180
But I didn't help and even looking on the net I didn't find anything useful.
The strangest thing is that I can't replicate this problem. In fact, locally, with the same configuration, I have no problem.
One possible hypothesis about that Call to undefined method ReflectionUnionType::getName () is that somewhere there might be something like:
public function myMethod(): int | float
but I have checked the code and I am not aware of any of this.
Can anyone help me debug?
These are unrelated separate problems. You’ll have higher luck asking about them in Psalm and PHPStan GitHub issue trackers.
We are currently using Nginx as our server and memcached for caching mechanism. I was inspecting PHP error logs and lots of PHP Warnings about memcached caught my attention.
PHP Warning: Memcache::get(): Invalid Memcache->connection member variable in {directory}/library/Zend/Cache/Backend/Memcached.php on line 180
At the line it was pointing, there is this piece of code:
$tmp = $this->_memcache->get($id);
I also see many other PHP warnings with the same warning message but different with different function calls of memcache object:
PHP Warning: Memcache::add(): Invalid Memcache->connection member variable in {directory}/library/Zend/Cache/Backend/Memcached.php on line 180
PHP Warning: Memcache::set(): Invalid Memcache->connection member variable in {directory}/library/Zend/Cache/Backend/Memcached.php on line 230
PHP Warning: Memcache::delete(): Invalid Memcache->connection member variable in {directory}/library/Zend/Cache/Backend/Memcached.php on line 323
I did a search through the web but could not find anything that really helped. From time to time, we have some problems with our memcached. Is it possible that this some kind of issue that happens when servers are down because of some problem? I really do not have any idea about what causes these warnings. How can I correct it or at least how can I avoid these warnings?
I found 3 references that might help you
Limit of file system and memcache
Possible memory leaks
Memcache vs Memcached
You need to check key max 250 chars and value max : 1MB
Have you compiled your own php recently? It's possible ther versions are out of sync.
I had the same problem.
when i called memcache object in __destruct to update the state of my object i goot the error.
and here is my solution.:
call object in your class function where you change the state and be sure to send an instance of memcache to this class.
While from the warning message itself, it may not be obvious, but the error may be happening when you're trying to serialize/deserialize memcache connection object itself.
For example:
class a {
private Memcache $mc;
private $name = 'glen';
public function __construct(Memcache $mc) {
$this->mc = $mc;
}
}
$a = new a($mc);
$mc->set('a', $a);
You very likely (as me) ended up here because class having mixed concerns (the object being a model and has as other business logic as well). you can omit the unwanted mc key from serializing using __debugInfo function:
public function __debugInfo() {
return [];
}
https://www.php.net/manual/en/language.oop5.magic.php#object.debuginfo
While writing this note, I'm not able to reproduce with my own example, so there's something else involved, perhaps memory corruption. But removing $mc property solve the problem for me.
I use sphinx php api as a service in a symfony2 project when I want to search a term in an index i got this warning
Warning: Invalid argument supplied for foreach() in /var/www/domain.com/Symfony2/src/project/myBundle/services/SphinxClient.php line 997
this is the line 997
foreach ( $this->_weights as $weight )
so I added a test befor foreach() like this if(!empty($this->_weights))
the same error appaires in each foreach so I added the same test.
then an other error appaires
Notice: Undefined property: prject\MyBundle\services\SphinxClient::$_socket in in /var/www/domain.com/Symfony2/src/project/myBundle/services/SphinxClient.php line 563
I was loking for the problem origin for hours.
thanks for your help in advance.
In sphinxapi.php file used old constructor.
Delete string ( near 430 )
function SphinxClient()
and write:
public function __construct()
and all very well.
Don't forget to set namespace in file (I renamed sphinxapi.php to SphinxClient.php) and write in begin it:
namespace Acme\MyBundle\Sphinx;
Your path may be something else.
Without seeing the source of the file, not a lot can do to help.
IN the standard sphinxapi.php class that comes with sphinx the varaiables are all class variables, so $this->_weigths is an array. Maybe that was missed when it was poted to Symfony
I am learning symfony2 and atfer creating some Doctrine Entities in a bundle, I wanted to move them.
However, after moving, and changing any instances of them being referenced, I was getting errors when trying to run my application.
I moved them back, and everything was fine.
Now I am just tyring to remove them completly, but again, I get errors when doing so.
Any help on removing Entities entirely?
I did exactly the same thing that Mr Pablo did, but for a bundle : I moved a bundle (renamed) and modified all calls to it.
I have the same error :
ErrorException: Catchable Fatal Error: Object of class __PHP_Incomplete_Class could not be converted to string in /Volumes/Data/home/timi/Sites/symfony2/vendor/symfony/src/Symfony/Component/Security/Core/Authentication/Token/AbstractToken.php line 70
in /Volumes/Data/home/timi/Sites/symfony2/vendor/symfony/src/Symfony/Component/HttpKernel/Debug/ErrorHandler.php line 65
at ErrorHandler->handle() in /Volumes/Data/home/timi/Sites/symfony2/vendor/symfony/src/Symfony/Component/Security/Core/Authentication/Token/AbstractToken.php line 70
at AbstractToken->getUsername() in /Volumes/Data/home/timi/Sites/symfony2/vendor/symfony/src/Symfony/Bundle/SecurityBundle/DataCollector/SecurityDataCollector.php line 56
at SecurityDataCollector->collect() in /Volumes/Data/home/timi/Sites/symfony2/vendor/symfony/src/Symfony/Component/HttpKernel/Profiler/Profiler.php line 174
at Profiler->collect() in /Volumes/Data/home/timi/Sites/symfony2/vendor/symfony/src/Symfony/Component/HttpKernel/EventListener/ProfilerListener.php line 90
at ProfilerListener->onKernelResponse()
at call_user_func() in /Volumes/Data/home/timi/Sites/symfony2/vendor/symfony/src/Symfony/Bundle/FrameworkBundle/Debug/TraceableEventDispatcher.php line 82
at TraceableEventDispatcher->doDispatch() in /Volumes/Data/home/timi/Sites/symfony2/app/cache/dev/classes.php line 3678
at EventDispatcher->dispatch() in /Volumes/Data/home/timi/Sites/symfony2/app/cache/dev/classes.php line 4754
at ContainerAwareEventDispatcher->dispatch() in /Volumes/Data/home/timi/Sites/symfony2/app/cache/dev/classes.php line 3904
at HttpKernel->filterResponse() in /Volumes/Data/home/timi/Sites/symfony2/app/cache/dev/classes.php line 3896
at HttpKernel->handleRaw() in /Volumes/Data/home/timi/Sites/symfony2/app/cache/dev/classes.php line 3846
at HttpKernel->handle() in /Volumes/Data/home/timi/Sites/symfony2/app/cache/dev/classes.php line 4791
at HttpKernel->handle() in /Volumes/Data/home/timi/Sites/symfony2/app/bootstrap.php.cache line 547
at Kernel->handle() in /Volumes/Data/home/timi/Sites/symfony2/web/app_dev.php line 20
Some help will be very welcomed :)
EDIT:
Well I solved the problem, Adam Stacey had heard it well :)
Before changing anything, I was logged in the website, by using FOSUserBundle firewall.
By changing the name of the bundle, it fooled the firewall and it was stuck at line 70 of ./vendor/symfony/src/Symfony/Component/Security/Core/Authentication/Token/AbstractToken.php
Here is the function :
public function getUsername()
{
if ($this->user instanceof UserInterface) {
return $this->user->getUsername();
}
return (string) $this->user;
}
So I commented out the line return (string) $this->user;, reloaded the webpage, logged out, than reverted the comment. And voilà !
What kind of errors were you getting?
Make sure you:
Clear cache
Rebuild database
Don't have any entity relationships with it
Don't have any code based on the entities
Like Inori mentioned have you tried rebuilding your entities?
If not try this from the CLI:
php app/console doctrine:generate:entities Acme
php app/console doctrine:schema:update --force
Replace "Acme" with your name, company name or whatever you have used in your bundles.
The other thing you may have to do is remove any instances where you have used the entities.
For example, you may have some entities in the controllers that look like this:
use Acme\BundleName\Entity\SomeEntity;
use Acme\BundleName\Entity\AnotherEntity;
They will need to be removed.
If you have the details of the particular errors that are coming up let me know what they are and I will try and help you further.
I have heard that this can also sometimes be to do with sessions. Are you using any bundles for authentication or anything like that?
In your php.ini file do you have your set to:
session.auto_start = Off
This may be way off, but worth a go. Let me know.
On a separate note. Did your server setup pass the checks in the app/check.php file that you can run via CLI?
if (class_exists('PhpThumb')) {
$pt = PhpThumb::getInstance();
$pt->registerPlugin('GdReflectionLib', 'gd');
}
if (in_array('PhpThumb', get_declared_classes())) {
$pt = PhpThumb::getInstance();
$pt->registerPlugin('GdReflectionLib', 'gd');
}
Either of these codes blocks throw the following error: "PHP Fatal error: Class 'PhpThumb' not found"
Can anyone explain why? Is this a bug in PHP?
I've encountered the same bug. In my case problem was due to mixed Russian and English letters in class name which looks similar.
I had a legacy code running under a newer version of PHP (5.3.10). I had some require_once() statements that was not doing their job. As I could change, I changed them do include() and it worked again.
I guess it have something to do with the PHP version, because running under a previous version the website was ok.
This happened for me when I was requiring a file not needed by a phpunit class I was running. The file was there, but I got the error.
Yet for a test that does need that class, the same include call works.
My work around was to have 2 config files, where 1 requires that class file and the 2nd file doesn't. So when not needed, I use the latter.
A little clunky with 1 extra small file (that I shouldn't have to create .. cse' la vie), but unblocks the issue here
After spending few hours on practicing with this mistakefullish fatal error...I've admitted that this function doesn't work with SPL autoload! And I've finally found a solution :
I replace 'class_exists()' by 'file_exists()' with a little bit more process to find out the real path of the class file (my classes have the same name as their filename).
Hope it helps.