ZF1: E_STRICT messages still appear after disabling - php

While migrating to a new host with PHP 5.4.x from old host with 5.3.x. I'm stumbling into a problem with E_STRICT.
I know that E_STRICT became part of E_ALL as of PHP 5.4, thus I have disabled it in php.ini.
But I still get an error in combination with Zend_Session, meaning the first page load is ok, I get the frontpage. If I refresh or go to another subpage I get the following error:
Fatal error: Uncaught exception 'Zend_Session_Exception' with message
'Zend_Session::start() -
/var/www/vhost/dev3_domain_com/httpdocs/application/models/someapi.php(
Line:4): Error #2048 Declaration of Someapi::getBeverageSizes() should
be compatible with
My_Service_Someapi::getBeverageSizes($storenumber, $ordertype)
/var/www/vhost/dev3_domain_com/httpdocs/application/models/someapi/Order
.php(Line:1039): Error #2 Creating default object from empty value
/var/www/vhost/dev3_domain_com/httpdocs/application/models/someapi/Order
.php(Line:1039): Error #2 Creating default object from empty value' in
/var/www/vhost/dev3_domain_com/httpdocs/library/Zend/Session.php:490
Stack trace: #0
/var/www/vhost/dev3_domain_com/httpdocs/library/Zend/Session/Namespace.
php(143): Zend_Session::start(true) #1
/var/www/vhost/dev3_domain_com/httpdocs/application/Bootstrap.php(213):
Zend_Session_Namespace->__construct('someapi') #2
/var/www/vhost/dev3_domain_com/httpdocs/library/Zend/Application/
Bootstrap/BootstrapAbstract.php(669): Bootstrap->_initO in
/var/www/vhost/dev3_domain_com/httpdocs/library/Zend/Session.php on line 490
I know I could/should fix my code, but it's quite tedious. The "Someapi" class is extended from "My_Service_Someapi" which in turn is extended from "Zend_Rest_Client" - to handle the webservice from our backend system.
Could it be that Zend Framework sets it's own error reporting? I know from other SO-posts that CakePHP does that.

Related

Duplicate entries in PHP error_log using set_exception_handler

I cannot seem to locate the source of this issue. I actually have nearly the same Docker container and Exception handler lib running in another app. However, for some reason, I'm getting duplicate log entries in the error log file.
The issue is that it's not just duplicate entries that are the same (that'd be another interesting issue). It's the same Exception being logged and the same stack trace, but one is from my custom Exception handler (JSON), and the other is the default PHP error log handler (or so it seems - tested with CLI SAPI as well as PHP-FPM).
I was under the assumption that PHP wouldn't write to the log file if an exception handler was set. I'm also executing die(1) at the end of the callback function for the Exception handler.
Again, all of the Exception handling code seems to be working well. It's just that PHP is still logging the Exception. Is there a setting or something else that I'm missing here needing to be done on the PHP config side?
Below is a copy of the error log output:
[24-Nov-2018 02:20:11 UTC] PHP Exception: Testing in /srv/www/boot/common.php on line 65
[24-Nov-2018 02:20:11 UTC] PHP Stack trace:
[24-Nov-2018 02:20:11 UTC] PHP 1. {main}() /srv/www/public/index.php:0
[24-Nov-2018 02:20:11 UTC] PHP 2. require() /srv/www/public/index.php:13
{"timestamp":"2018-11-24 02:20:11 UTC","level":"critical","message":"Testing","app_version":{},"environment":"dev","class":"Exception","file":"\/srv\/www\/boot\/common.php","line":65,"code":0,"previous":null,"trace":[{"file":"\/srv\/www\/public\/index.php","line":13,"function":"require"}],"user":[],"tags":[],"extra":[],"output_buffers":[]}
Going to leave this here for anyone that might come across this. The issue turned out to be XDebug which hijacks your Exceptions. It was enabled on this particular app in our dev env.

Fatal error because an Error instance is being passed instead of an expected Exception instance

I just installed xampp with php 7.0.4 and a fresh cakephp 3.2.6.
I did a lot of research and everything I found shows that they are compatible.
However as soon as I go to open the application with a browser, cake replies with an Internal Error.
The only pointer as to what to do is that xampp logs the following in apache error.log:
PHP Fatal error: Uncaught TypeError: Argument 1 passed to Cake\Error\BaseErrorHandler::handleException() must be an instance of Exception, instance of Error given in D:\Xampp\htdocs\cakephp\vendor\cakephp\cakephp\src\Error\BaseErrorHandler.php:153
Stack trace:
#0 [internal function]: Cake\Error\BaseErrorHandler->handleException(Object(Error))
#1 {main} thrown in D:\Xampp\htdocs\cakephp\vendor\cakephp\cakephp\src\Error\BaseErrorHandler.php on line 153
I tried php 5.6 but it still shows the error in the log.
If that's the error that you are encountering, then I'd doubt that you are using CakePHP 3.2.6, as line 153 is in the middle of a comment
https://github.com/cakephp/cakephp/blob/3.2.6/src/Error/BaseErrorHandler.php#L153
PHP7 errors are handled since CakePHP 3.1.5, so check your CakePHP dependency, and make sure it's actually up to date.

Getting 500 Internal Server Error with Stripe

I am trying to implement basic functionality of the Stripe API, I get 500 Internal Server Error for some reason when I require the Stripe.php file that you have to require...When I comment the require out the error goes away but obviously I can not use the API then..
Basic require...shows error in the Modal Log
require_once('/php/Stripe.php');
I checked the server error and it gave me this back
Fatal error: Uncaught exception 'Exception' with message 'Stripe needs the Multibyte String PHP extension.' in /php/Stripe.php:13 Stack trace: #0 /home/stripepost.php(4): require_once() #1 {main} thrown in /php/Stripe.php on line 13
This all comes from just requiring the file..
Is your 'Stripe.php' file really located in '/php' or is it in a folder called 'php' local to your code?
Current code:
require_once('/php/Stripe.php');
I think the problem is this. You probably mean to use something relative to your code base. Like this:
require_once('./php/Stripe.php');
I found out the answer I didn't have the mbstring enabled on my server...whooops

Can't stop SwiftMailer Exceptions Being Displayed to Browser in Laravel

I am using Laravel for a site. I have a page where users can contact me. This sends me an email using the SwiftMailer bundle. It has just been brought to my attention that the following error is seen when trying to send a message
Fatal error: Uncaught exception 'Swift_TransportException'
Exception thrown from here /Applications/MAMP/htdocs/yooies_site/bundles/swiftmailer/library/classes/Swift/Transport/Esmtp/AuthHandler.php on line 176
Code at this location is:
throw new Swift_TransportException(
'Failed to authenticate on SMTP server with username "' .
$this->_username . '" using ' . $count . ' possible authenticators'
);
The cause of the error is not a worry (I found out that I had change my mail password and forgot to change in my sites email config)
The issue I have is that I have Laravel setup to log any exceptions and NOT display them on the main page. I have the following setup in my error.php config file
'detail' => false,
'log' => true,
Why then is my site showing the exception on the page instead of a 500 error?
Full stack trace here (Note I have removed my sites real name and replaced with 'site'
Fatal error: Uncaught exception 'Swift_TransportException'
with message 'Failed to authenticate on SMTP server with username "info+site.com" using 2 possible authenticators'
in /Applications/MAMP/htdocs/site/bundles/swiftmailer/library/classes/Swift/Transport/Esmtp/AuthHandler.php:176
Stack trace:
#0 /Applications/MAMP/htdocs/site/bundles/swiftmailer/library/classes/Swift/Transport/EsmtpTransport.php(307): Swift_Transport_Esmtp_AuthHandler->afterEhlo(Object(Swift_SmtpTransport))
#1 /Applications/MAMP/htdocs/site/bundles/swiftmailer/library/classes/Swift/Transport/AbstractSmtpTransport.php(124): Swift_Transport_EsmtpTransport->_doHeloCommand()
#2 /Applications/MAMP/htdocs/site/bundles/swiftmailer/library/classes/Swift/Mailer.php(79): Swift_Transport_AbstractSmtpTransport->start()
#3 /Applications/MAMP/htdocs/site/application/libraries/personal/mailer.php(55): Swift_Mailer->send(Object(Swift_Message))
#4 /Applications/MAMP/htdocs/site/application/config/error.php(91): Personal\Mai in /Applications/MAMP/htdocs/site/bundles/swiftmailer/library/classes/Swift/Transport/Esmtp/AuthHandler.php on line 176
Laravel version is L3.
Bundle URL here http://bundles.laravel.com/bundle/swiftmailer
Swiftmailer doesn't touch any configuration that's responsible for showing errors. Among the recommendations for production servers is to have display_errors = Off and display_startup_errors = Off, which can be set in php.ini, httpd.conf, .htaccess, .user.ini, etc, or even using ini_set(). You should make sure these directives are correctly set.
I'm not familiar with how Laravel handles exceptions and errors, but it looks like the Swift_TransportException is thrown outside of Laravel's error-handling process. Can you point out where in the flow of the application the exception is thrown? Maybe a stack-trace?
PS: Just a tip: Things like sending emails are better not done during a request at all. You could offload it to some sort of queue, and have another process on the server handle it. You could take a look at Gearman for this.
update
Looking at the stack-trace, it seems Laravel does catch the exception because Log::exception(); is invoked (in application/config/error.php line 91). But the trace doesn't reveal how it got there. Maybe you can run it on a development machine where you have Xdebug installed. Xdebug will give you a more precise stack-trace when the exception is throws, ending with public/index.php (where the request started).

Doctrine error when deploying symfony2 app on pagoda box

I'm getting a doctrine error after deploying my app on PagodaBox. It works fine in both dev and prod environments on my local machine but the live site returns this error:
Fatal error: Uncaught exception 'LogicException' with message 'Illegal value passed (no array or string given)' in /var/www/vendor/doctrine/doctrine-bundle/Doctrine/Bundle/DoctrineBundle/DoctrineBundle.php:101 Stack trace: #0 /var/www/vendor/doctrine/doctrine-bundle/Doctrine/Bundle/DoctrineBundle/DoctrineBundle.php(101): spl_autoload_register(NULL) #1 /var/www/app/bootstrap.php.cache(2275): Doctrine\Bundle\DoctrineBundle\DoctrineBundle->boot() #2 /var/www/app/bootstrap.php.cache(2303): Symfony\Component\HttpKernel\Kernel->boot() #3 /var/www/web/app.php(23): Symfony\Component\HttpKernel\Kernel->handle(Object(Symfony\Component\HttpFoundation\Request)) #4 {main} thrown in /var/www/vendor/doctrine/doctrine-bundle/Doctrine/Bundle/DoctrineBundle/DoctrineBundle.php on line 101
The cache is cleared every time the app is deployed.
Any suggestions would be gratefully received because I'm totally stumped!
UPDATE:
I've done some more debugging and I have discovered that even in the prod environment the kernel.cache_dir parameter is set to /var/www/app/cache/dev. This means that the doctrine cache dir is being incorrectly set as it relies on this other parameter. I thought the kernel.cache_dir was set automatically depending on the environment.
I finally got this sorted. It was down to using eAccelerator as my opcode cache. It turns out that there is a bug in eAccelerator that means it can't process closures correctly. I'm now using XCache and it is all working fine.
This is the auto-loading failing in DoctrineBundle.php Line 101:
$this->autoloader = Autoloader::register($dir, $namespace, $proxyGenerator);
Your passing NULL to the $dir argument, which judging by the exception its requires either an array() or string.
You can see that the method uses $dir from the configuration variable doctrine.orm.proxy_dir (Line 64).
$dir = $this->container->getParameter('doctrine.orm.proxy_dir');`
My guess is that you have not defined this path correctly
Edit - Take a look here for Doctrine's configuration which includes the proxy_dir setting.

Categories