PHP: MDB2 error - call to undefined function - php

I have error in my old project based od MDB2 and PHP 5.4:
PHP Fatal error: Call to undefined function: MDB2_Driver_pgsql::raiseError(). in /path/to/project/vendor/pear-pear.php.net/MDB2/MDB2.php on line 1936
Dependencies loaded via composer:
"require": {
"pear-pear.php.net/Validate": "0.7.0",
"pear-pear.php.net/Validate_PL": "0.5.1",
"pear-pear.php.net/HTML_Quickform": "*",
"pear-pear.php.net/HTML_Table": "*",
"pear-pear.php.net/MDB2": "*",
"pear-pear.php.net/MDB2_Driver_pgsql": "*",
"pear-pear.php.net/OLE": "1.0.0RC1",
"pear-pear.php.net/Spreadsheet_Excel_Writer": "0.9.1",
"pear-pear.php.net/File_SearchReplace": "*",
And I don't change anything in this code. Anyone had this problem? :)

This error is solved by installing PEAR-1.9.5
I've spent some time to find easy way to downgrade PEAR version.
It's easy to do by running terminal command:
pear install -f PEAR-1.9.5
Hope this will help someone to save extra time.

Related

500 Error when testing monlog package

I'm trying to test out the monolog package using composer (full disclosure: this is my first try using composer) and am getting a 500 error when running this code:
<?php
// composer autoloader
require_once 'vendor/autoload.php';
// Shortcuts for simpler usage
use \Monolog\Logger;
use \Monolog\Formatter\LineFormatter;
use \Monolog\Handler\StreamHandler;
// Common logger
$log = new Logger('files');
// Line formatter without empty brackets in the end
$formatter = new LineFormatter(null, null, false, true);
// Debug level handler
$debugHandler = new StreamHandler('debug.log', Logger::DEBUG);
$debugHandler->setFormatter($formatter);
// Error level handler
$errorHandler = new StreamHandler('error.log', Logger::ERROR);
$errorHandler->setFormatter($formatter);
// This will have both DEBUG and ERROR messages
$log->pushHandler($debugHandler);
// This will have only ERROR messages
$log->pushHandler($errorHandler);
// The actual logging
$log->debug('I am debug');
$log->error('I am error', array('productId' => 123));
?>
I see in Dreamweaver that the three 'use' lines in monolog_test.php are highlighted in red:
The error message is:
In my /Applications/MAMP/logs/php_error.log:
[03-Mar-2018 14:10:05 America/Toronto] PHP Fatal error: Class
'Monolog\Logger' not found in
/Users/Ross/Dropbox/htdocs/wonderfest/secure/contest/monolog_test.php
on line 13
My file system setup looks like this:
I installed Composer globally on my Mac and I know the installation is good because I was able to add some packages using composer require . My composer.json file:
{
"require": {
"monolog/monolog": "1.0",
"phpfastcache/phpfastcache": "^6.1",
"mpdf/mpdf": "^7.0"
}
}
And my vendor\autoload.php:
<?php
// autoload.php #generated by Composer
require_once __DIR__ . '/composer/autoload_real.php';
return ComposerAutoloaderInit348f040c8a2a7d48c0a311fb1af10c08::getLoader();
I guess my question is this: do I have to do anything other than install packages to make their namespaces available?
I updated monolog to the latest stable version and although the 3 'use' lines in Dreamweaver still show up as errors, it works. What threw me was this line on the monolog package page:
Monolog works with PHP 7.0 or above, use Monolog ^1.0 for PHP 5.3+ support.
I thought that meant that I needed to use v1.0 for my PHP 5.6.32, but when I removed that version constraint from the require command everything seems to work - I get the two logs in the same folder as the monolog_test.php file.
My new composer.json (with one additional packages installed):
{
"require": {
"monolog/monolog": "^1.23",
"mpdf/mpdf": "^7.0",
"phpfastcache/phpfastcache": "^6.1",
"phpmailer/phpmailer": "^6.0"
}
}

pdftk: PHP Fatal error: Class 'mikehaertl\pdftk\Pdf' not found in

I have a project in Slim framework. There are multiple composer packages. Now, I have added https://github.com/mikehaertl/php-pdftk to fill PDF but I'm getting PHP Fatal error: Class 'mikehaertl\pdftk\Pdf' not found in... What is wrong with my code?
composer.json:
{
"require": {
"dibi/dibi": "^3.0",
"slim/slim": "^3.7.0",
"phpmailer/phpmailer": "^5.2",
"jbroadway/urlify":"^1.1.0",
"simplesoftwareio/simple-qrcode":"^1.5.1",
"gopay/payments-sdk-php":"^1.2.3",
"mikehaertl/php-pdftk":"^0.4.2"
}
}
in my ./config/config.php there is:
define('PATH', dirname(__DIR__));
require_once PATH."/vendor/autoload.php";
and in my ./methods/controller.php:
...
$pdf = new mikehaertl\pdftk\Pdf("/path/to/QR_template.pdf");
...
I tried to get names of all included files by using:
var_dump(get_included_files());
but the "pdf" files were not in the array.
Other packages works well but pdftk not. Where is the problem?
Thank you.
Solved! The problem was composer version. Composer self-update solved the problem.

Trying to run heroku locally and get a error 'vendor' is not a command

I am trying to run heroku locally using the command
heroku local
However, it returns:
[OKAY] Loaded ENV .env File as KEY=VALUE Format
'vendor' is not recognized as an internal or external command, operable program or batch file.
[DONE] Killing all proccess with signal null
Exited with exit code 1
I am using Heroku PHP within Windows 7
In my PATH environmental variable, I have both:
./vendor/bin and C:\Users\user-name\AppData\Roaming\Composer\vendor\bin
(The last one is an empty folder)
I searched for anything similar but I couldn't find.
Any thoughts on it?
Thanks in advance
Update
The error was in my Procfile:
web: vendor/bin/heroku-php-apache2 public/
Then I change all slashes to backslashes ():
web: vendor\bin\heroku-php-apache2 public\
Now its working but I am getting this error:
../heroku/heroku-buildpack-php/bin/heroku-php-apache2: line 196: php-fpm: command not found
This program requires PHP 5.5.11 or newer; check your 'php-fpm' command.
I think there is something wrong related to my composer.
The source file for heroku-php-apache2 can be found here.
The line 196 is presented below.
196: { php-fpm -n -v | php -n -r 'exit((int)version_compare(preg_replace("#PHP (\S+) \(fpm-fcgi\).+$#sm", "\\1", file_get_contents("php://stdin")), "5.5.11", "<"));'; } || { echo "This program requires PHP 5.5.11 or newer; check your 'php-fpm' command." >&2; exit 1; }
My composer.json file is:
{
"require" : {
"ext-mcrypt": "*",
"facebook/php-sdk-v4" : "~5.0",
"google/apiclient": "2.0"
},
"require-dev": {
"mashape/unirest-php": "3.*",
"heroku/heroku-buildpack-php": "*"
}
}
I tried to specific require php in composer.json but it didn't changed. Any thoughts on that?
Thank you in advance.
Years later, I've faced this same issue.
Fixed by removing vendor/ and running composer install again.
Then I've faced the same php-fpm error and to fix that I created a symbolic link from /usr/sbin/php-fpm7.4 -> /usr/sbin/php-fpm.
Hope that becomes helpful to orthers in the future!

Need help in overcoming the incompatibility of a certain behat dependencies set with a PHP 5.3

I was having a certain behat configuration with a specific dependencies set which worked well with PHP 5.5. But later I've had to transfer that configuration to a server with jenkins. The trouble is that server has PHP 5.3 installed with no possibility to be updated.
Despite dependencies refused to be installed via composer in a normal way, I've forced them to be installed anyway using the "--ignore-platform-reqs" parameter.
Having installed the dependencies, I've faced with another issue which I could not had overcome that easily. It simply displays an error while attempting to execute "bin/behat" command:
PHP Parse error: syntax error, unexpected '[' in .../workspace/automated-tests/vendor/guzzlehttp/psr7/src/functions.php on line 77
PHP Stack trace:
PHP 1. {main}() .../workspace/automated-tests/vendor/behat/behat/bin/behat:0
PHP 2. includeIfExists() .../workspace/automated-tests/vendor/behat/behat/bin/behat:21
PHP 3. include() .../automated-tests/vendor/behat/behat/bin/behat:17
PHP 4. ComposerAutoloaderInit617eef80953ba1e8b93feeaeccb52bc0::getLoader() .../workspace/automated-tests/vendor/autoload.php:7
PHP 5. composerRequire617eef80953ba1e8b93feeaeccb52bc0() .../workspace/automated-tests/vendor/composer/autoload_real.php:49
PHP 6. require() .../workspace/automated-tests/vendor/composer/autoload_real.php:59
Parse error: syntax error, unexpected '[' in .../workspace/automated-tests/vendor/guzzlehttp/psr7/src/functions.php on line 77 Call Stack: 0.0006 645368 1. {main}() .../workspace/automated-tests/vendor/behat/behat/bin/behat:0 0.0008 645976 2. includeIfExists() .../workspace/automated-tests/vendor/behat/behat/bin/behat:21 0.0016 649328 3. include('.../workspace/automated-tests/vendor/autoload.php') .../workspace/automated-tests/vendor/behat/behat/bin/behat:17 0.0021 680968 4. ComposerAutoloaderInit617eef80953ba1e8b93feeaeccb52bc0::getLoader() .../workspace/automated-tests/vendor/autoload.php:7 0.0082 1106296 5. composerRequire617eef80953ba1e8b93feeaeccb52bc0() .../workspace/automated-tests/vendor/composer/autoload_real.php:49 0.0089 1109928 6. require('.../workspace/automated-tests/vendor/guzzlehttp/psr7/src/functions_include.php') .../automated-tests/vendor/composer/autoload_real.php:59
Here's the list of dependencies in composer.json:
{
"require": {
"behat/gherkin": "~4.4",
"drupal/drupal-extension": "~3.1",
"emuse/behat-html-formatter": "dev-master"
},
"require-dev": {
"bossa/phpspec2-expect": "~1.0",
"ocramius/proxy-manager": "~0.5",
"phpunit/phpunit": "~4.5",
"jakoch/phantomjs-installer": "1.9.8"
},
"autoload": {
"psr-0": {
"Behat\\Behat": "src/",
"Behat\\Testwork": "src/"
}
},
"config": {
"bin-dir": "bin/"
}
}
Short array syntax [] was added in PHP 5.4, so I guess you're running some older version of PHP on the shared server. Normally replacing [] with array() would help, but here it is an external vendor package so it's not advised to modify the code as changes would be overwritten when vendor package is updated. Other than that the only way to fix that issue is to use newer version of PHP.
From this related question
I've found a solution to the problem. I've changed the "require" block in composer.json to the following:
{
"require": {
"drupal/drupal-extension": "*",
"emuse/behat-html-formatter": "dev-master"
},
Notice that I've got rid of the ""behat/gherkin": "~4.4"" and changed drupal/extension version to "*". Thus it downloads the latest and most stable version along with all dependencies it requires (so behat 4 is included as well) according to the specs of my system (so its PHP 5.3 compatible).
At least that's the way I see it. Please, correct me If I'm wrong.

Intervention causing reload of page?

I'm probably using it wrong and not understanding the purpose properly. But as a simple test, I added the following in my "master.blade.php" file:
if (!file_exists('images/cache/clients/'.$image)) {
$img = Image::make('images/clients/'.$image)->resize(null, 50, true);
$img->save('images/cache/clients/'.$image);
}
The problem is that when it hits this code, it basically reloads the entire frontpage. SO I see the content twice. It's like the make function actually does some header response of some kind.
All I want to do is resize the image, and save it to another location. What am I missing?
UPDATE
I have this in my composer.json file:
"require": {
"laravel/framework": "4.1.*",
"way/generators": "dev-master",
"laravelbook/ardent": "dev-master",
"codesleeve/stapler": "dev-master",
"phpseclib/phpseclib": "0.3.*",
"chumper/datatable": "dev-master",
"moltin/laravel-cart": "dev-master",
"intervention/image": "1.*",
"opauth/opauth": "0.4.x",
"artdarek/oauth-4-laravel": "dev-master"
},
I am unsure whether this should be added anywhere:
use Intervention\Image\Image;
(this page isn't exact if this should be added for laravel, or where it should be added for laravel)
I've got:
GD bundled (2.1.0 compatible)
PHP 5.5.11
Any ideas what's wrong?
UPDATE2
Make just does this:
public static function make($source)
{
return new static($source);
}
I've tried wrapping make around an exception, no luck. But even if I do this:
public static function make($source)
{
$bla = new static($source);
print 'xxx'; die();
}
I don't see the print 'xxx' happening. If I put it before the "new static" part, I do see it. So basically, it's bombing on "new static". Is there any reason why this should happen on PHP 5.5?
** THINK I GOT IT **
I took everything out and placed it before the app even runs. Now I get this error:
Symfony \ Component \ Debug \ Exception \ FatalErrorException
Call to undefined function Intervention\Image\finfo_buffer()
This is saying libjpeg might be the issue, but it seems I do have it in my PhpInfo:
libJPEG Version 9 compatible
I'm running xampp, and apparrently I need this in the php.ini file:
extension=php_fileinfo.dll
I've added it but have to restart my machine to see the effect (dont ask, my xampp is broken)... will report back in a sec.
The problem was not having fileinfo enabled. I added this in my php.ini file:
extension=php_fileinfo.dll
That did the trick. A bit of a bummer that the addon didn't make it apparent.
Thanks for the downvote, but I'm sure this will help someone else trouble-shoot this problem.

Categories