php-initial-avatar-generator icon indicating copy to clipboard operation
php-initial-avatar-generator copied to clipboard

Update InitialAvatar.php

Open pobegov opened this issue 2 years ago • 4 comments

Discovered when porting an existing project to PHP 8.1.

It seems that with open_basedir restrictions set, a call to file_exists() to any path outside of the paths set in open_basedir setting, a warning will be thrown. Which is not very clean.

also is there a linux/unix box where there is a directory on root level called /fonts/? I do not know any... so commenting this case out :)

pobegov avatar Nov 30 '22 12:11 pobegov

Hm... "continuous-integration/styleci/pr — Issues have been identified with 1 file" is funny, shows me a diff of the whole file as if I have modified it's styling. Which is not true, you can see on the only commit that I made ... I have only added two lines of code. Something is fishy somewhere

pobegov avatar Jan 23 '23 15:01 pobegov

Hi, thanks for this!

Where is "/fonts/" called?

I only see it with current directory appended (DIR), or dependent on set value.

I'll move to 8.1 soon, so will test it out and see what happens -- and try with this PR as well

You can ignore the CI part 👍🏻 I should be able to ask it to format code before merge.

LasseRafn avatar Jan 23 '23 16:01 LasseRafn

In the latest version which I've got from composer, in the file

src/InitialAvatar.php

on line 677 there is the following check:

if ( file_exists( $fontFile ) ) { ... }

which is then followed by two further checks prepending the DIR and also a slash

if ( file_exists( __DIR__ . $fontFile ) ) { ... } if ( file_exists( __DIR__ . '/' . $fontFile ) ) { ... }

the first check which attempts to see if the font-file exists actually looks in a directory relative to "/", which was totally fine until PHP 8.1, probably open_basedir was not throwing a warning if it could not check a location and returned false instead. The change in behaviour which came with PHP 8.1 always yields a warning. I have taken the liberty to remove the check completely, works like charm in my project with over 100K users.

Thank you for a great library!

pobegov avatar Jan 23 '23 16:01 pobegov