preg_replace passing null to parameter 3 is deprecated
akulmehta opened this issue ยท 4 comments
Have you searched through other issues to see if your problem is already reported or has been fixed?
Yes, I did not find it.
Did you read the documentation?
Yes, I did not find it.
Have you tried to publish the views?
Yes - I didn't work.
Is there an error in the console?
No
PHP Version
8.3.6
PowerGrid
5.4.10
Laravel
10.48.8
Livewire
3.4.6
Alpine JS
3.13.5
Theme
Bootstrap
Describe the bug.
In Laravel debugbar I noticed I am getting the warning messages like:
It seems there are several instances of preg_replace where the parameter #3 which is $content is passed and if this is null, it triggers this warning.
This can be easily fixed with using null coalescing with the $content like $content ?? ''
- I can create a PR for this if this sounds good.
To Reproduce...
- Install Laravel Debugbar
- Create a PowerGrid table with some values which are null.
- Observe error in messages tab of DebugBar.
Extra information
No response
I have PHP 8.2.x, bootstrap, Laravel Debugbar and cant reproduce that problem. Please tell me, what values are null in your example.
@marineusde I am on PHP 8.3.x Let's say you have a UserTable with datasource as:
/**
* PowerGrid datasource.
*
* @return Builder<\App\Models\User>
*/
public function datasource(): Builder
{
$query = User::query();
return $query;
}
and you have fields like:
public function fields(): PowerGridFields
{
$columnData = PowerGrid::fields()
->add('id')
->add('name')
->add('email')
->add('affiliation', fn () => null)
->add('created_at_formatted', fn (User $user) => Carbon::parse($user->created_at)->format('Y-m-d'));
return $columnData;
}
in the above, the affiliation field is transformed to null for illustrative purposes for all users, but in my app, affiliation can sometimes be null and sometimes not.
In such a case when the table is viewed you see the Message in the debugbar:
thanks for the example, but I cant reproduce it. Maybe cause I work with linux and older php version!? But if the changes helps you, its great ๐