JamesHeinrich / phpThumb

phpThumb() - The PHP thumbnail generator
Other
315 stars 97 forks source link

Deprecated: dirname(): Passing null to parameter #1 ($path) of type string is deprecated #188

Closed jamieburchell closed 2 years ago

jamieburchell commented 2 years ago

Using phpthumb v1.7.17 with PHP 8.1 I'm seeing the following deprecation notices, which look to be all related to a NULL being passed around somewhere:

Code I'm running:

$image = new phpthumb;
$image->setParameter('config_allow_src_above_docroot', true);
$image->resetObject();
$image->setSourceFilename('/path/to/my/image.jpg');
$image->setParameter('w', 100);
$image->setParameter('h', 100);
$image->setParameter('q', 100);
$image->GenerateThumbnail();
$image->RenderToFile('/path/to/output.jpg');

Deprecations:

( ! ) Deprecated: dirname(): Passing null to parameter #1 ($path) of type string is deprecated in /home/jamie/projects/x/vendor/james-heinrich/phpthumb/phpthumb.class.php on line 1411
Call Stack
...
7   0.0026  443816  phpthumb->setOutputFormat( )    .../phpthumb.class.php:365
8   0.0026  444600  phpthumb->ImageMagickVersion( $returnRAW = ??? )    .../phpthumb.class.php:1003
9   0.0026  445384  phpthumb->ImageMagickCommandlineBase( ) .../phpthumb.class.php:1530
10  0.0026  445968  phpthumb->file_exists_ignoreopenbasedir( $filename = NULL, $cached = ??? )  .../phpthumb.class.php:1469
11  0.0026  446784  dirname( $path = NULL ) .../phpthumb.class.php:1411

( ! ) Deprecated: file_exists(): Passing null to parameter #1 ($filename) of type string is deprecated in /home/jamie/projects/x/vendor/james-heinrich/phpthumb/phpthumb.class.php on line 1412
Call Stack
...
7   0.0026  443816  phpthumb->setOutputFormat( )    .../phpthumb.class.php:365
8   0.0026  444600  phpthumb->ImageMagickVersion( $returnRAW = ??? )    .../phpthumb.class.php:1003
9   0.0026  445384  phpthumb->ImageMagickCommandlineBase( ) .../phpthumb.class.php:1530
10  0.0026  445968  phpthumb->file_exists_ignoreopenbasedir( $filename = NULL, $cached = ??? )  .../phpthumb.class.php:1469
11  0.0027  446896  file_exists( $filename = NULL ) .../phpthumb.class.php:1412

( ! ) Deprecated: strtolower(): Passing null to parameter #1 ($string) of type string is deprecated in /home/jamie/projects/x/vendor/james-heinrich/phpthumb/phpthumb.class.php on line 1013
Call Stack
...
7   0.0026  443816  phpthumb->setOutputFormat( )    .../phpthumb.class.php:365
8   0.0101  451488  strtolower( $string = NULL )    .../phpthumb.class.php:1013

( ! ) Deprecated: substr(): Passing null to parameter #1 ($string) of type string is deprecated in /home/jamie/projects/x/vendor/james-heinrich/phpthumb/phpthumb.class.php on line 1060
Call Stack
...
7   0.0102  452432  phpthumb->SetCacheFilename( )   .../phpthumb.class.php:369
8   0.0102  452432  phpthumb->setCacheDirectory( )  .../phpthumb.class.php:3575
9   0.0102  452560  substr( $string = NULL, $offset = -1 )  .../phpthumb.class.php:1060

( ! ) Deprecated: is_dir(): Passing null to parameter #1 ($filename) of type string is deprecated in /home/jamie/projects/x/vendor/james-heinrich/phpthumb/phpthumb.class.php on line 1079
Call Stack
...
7   0.0102  452432  phpthumb->SetCacheFilename( )   .../phpthumb.class.php:369
8   0.0102  452432  phpthumb->setCacheDirectory( )  .../phpthumb.class.php:3575
9   0.0103  460752  is_dir( $filename = NULL )  .../phpthumb.class.php:1079

( ! ) Deprecated: round(): Passing null to parameter #1 ($num) of type int|float is deprecated in /home/jamie/projects/x/vendor/james-heinrich/phpthumb/phpthumb.class.php on line 1921
Call Stack
...
7   0.0104  461072  phpthumb->ExtractEXIFgetImageSize( )    .../phpthumb.class.php:371
8   0.0104  461888  phpthumb->ImageMagickThumbnailToGD( )   .../phpthumb.class.php:3454
9   0.0179  486944  round( $num = NULL )    .../phpthumb.class.php:1921

PHP ImageMagick info:

$ php -i | grep agic
/etc/php/8.1/cli/conf.d/20-imagick.ini,
libmagic => 540
imagick
imagick module => enabled
imagick module version => 3.6.0
imagick classes => Imagick, ImagickDraw, ImagickPixel, ImagickPixelIterator, ImagickKernel
Imagick compiled with ImageMagick version => ImageMagick 6.9.10-23 Q16 x86_64 20190101 https://imagemagick.org
Imagick using ImageMagick library version => ImageMagick 6.9.10-23 Q16 x86_64 20190101 https://imagemagick.org
ImageMagick copyright => © 1999-2019 ImageMagick Studio LLC
ImageMagick release date => 20190101
ImageMagick number of supported formats:  => 235
ImageMagick supported formats => 3FR, 3G2, 3GP, AAI, AI, ART, ARW, AVI, AVS, BGR, BGRA, BGRO, BIE, BMP, BMP2, BMP3, BRF, CAL, CALS, CANVAS, CAPTION, CIN, CIP, CLIP, CMYK, CMYKA, CR2, CRW, CUR, CUT, DATA, DCM, DCR, DCX, DDS, DFONT, DJVU, DNG, DOT, DPX, DXT1, DXT5, EPDF, EPI, EPS, EPS2, EPS3, EPSF, EPSI, EPT, EPT2, EPT3, ERF, EXR, FAX, FILE, FITS, FRACTAL, FTP, FTS, G3, G4, GIF, GIF87, GRADIENT, GRAY, GRAYA, GROUP4, GV, H, HALD, HDR, HISTOGRAM, HRZ, HTM, HTML, HTTP, HTTPS, ICB, ICO, ICON, IIQ, INFO, INLINE, IPL, ISOBRL, ISOBRL6, JBG, JBIG, JNG, JNX, JPE, JPEG, JPG, JPS, JSON, K25, KDC, LABEL, M2V, M4V, MAC, MAGICK, MAP, MASK, MAT, MATTE, MEF, MIFF, MKV, MNG, MONO, MOV, MP4, MPC, MPEG, MPG, MRW, MSL, MSVG, MTV, MVG, NEF, NRW, NULL, ORF, OTB, OTF, PAL, PALM, PAM, PANGO, PATTERN, PBM, PCD, PCDS, PCL, PCT, PCX, PDB, PDF, PDFA, PEF, PES, PFA, PFB, PFM, PGM, PGX, PICON, PICT, PIX, PJPEG, PLASMA, PNG, PNG00, PNG24, PNG32, PNG48, PNG64, PNG8, PNM, PPM, PREVIEW, PS, PS2, PS3, PSB, PSD, PTIF, PWP, RADIAL-GRADIENT, RAF, RAS, RAW, RGB, RGBA, RGBO, RGF, RLA, RLE, RMF, RW2, SCR, SCT, SFW, SGI, SHTML, SIX, SIXEL, SPARSE-COLOR, SR2, SRF, STEGANO, SUN, SVG, SVGZ, TEXT, TGA, THUMBNAIL, TIFF, TIFF64, TILE, TIM, TTC, TTF, TXT, UBRL, UBRL6, UIL, UYVY, VDA, VICAR, VID, VIFF, VIPS, VST, WBMP, WEBP, WMF, WMV, WMZ, WPG, X, X3F, XBM, XC, XCF, XPM, XPS, XV, XWD, YCbCr, YCbCrA, YUV
imagick.allow_zero_dimension_images => 0 => 0
imagick.locale_fix => 0 => 0
imagick.progress_monitor => 0 => 0
imagick.set_single_thread => 1 => 1
imagick.shutdown_sleep_count => 10 => 10
imagick.skip_version_check => 1 => 1
JamesHeinrich commented 2 years ago

If you're able to track down the problem and submit a patch that would be appreciated. I won't have access to a PHP8 environment for a while.

jamieburchell commented 2 years ago

@JamesHeinrich You need to make sure you're not passing NULL to dirname. I'm not sure why it is. dirname accepts a string only and in PHP 8.1 you'll get the deprecation notice.

It's going to be a wider issue anywhere you perform string or number functions on NULL (strtolower, preg_replace, round etc.). It looks like at least some of these NULLs are coming from the class property defaults.

bsakhanov commented 2 years ago

Good afternoon! On version php 8.1 there is also an error related to the deprecation of the function: Deprecated: strlen(): Passing null to parameter #1 ($string) of type string is deprecated in ...phpthumb.class.php on line 3516

catsmeatman commented 2 years ago

And this at php8.1 Deprecated: substr(): Passing null to parameter #1 ($string) of type string is deprecated on phpthumb.class.php on line 1060 Deprecated: is_dir(): Passing null to parameter #1 ($filename) of type string is deprecated on phpthumb.class.php on line 1079

yepkoo commented 2 years ago

You can use the file I attached to the topic below. It's working flawlessly for now.

https://github.com/JamesHeinrich/phpThumb/issues/187

JamesHeinrich commented 2 years ago

Issues probably resolved as discussed in https://github.com/JamesHeinrich/phpThumb/issues/187 Please reopen if you still have issues.