kartik-v / yii2-markdown

Advanced Markdown editing and conversion utilities for Yii Framework 2.0
http://demos.krajee.com/markdown
Other
89 stars 41 forks source link

PHP Deprecated Warning on trim() if $icon is null #76

Open sarahnekam opened 1 year ago

sarahnekam commented 1 year ago

Version 1.3.1 with PHP Version 8.1

If I use the following I got an ErrorException from Yii2

$form->field($mailtext, 'content')->widget(
    \kartik\markdown\MarkdownEditor::class,
    ['height' => 300, 'encodeLabels' => false]
);

PHP Deprecated Warning – [yii\base\ErrorException](https://www.yiiframework.com/doc-2.0/yii-base-errorexception.html) trim(): Passing null to parameter #1 ($string) of type string is deprecated

in \vendor\kartik-v\yii2-markdown\src\MarkdownEditor.php at line 378

{
     $icon = ArrayHelper::remove($options, 'icon', '');
     $label = ArrayHelper::remove($options, 'label', '');
     $encodeLabel = ArrayHelper::remove($options, 'encodeLabel', $this->encodeLabels);
     $options['type'] = 'button';
     $prefix = $this->getDefaultIconPrefix();
     if (strlen(trim($icon)) > 0) {
         $icon = "<i class='{$prefix}{$icon}'></i>";
     }
     if (strlen(trim($label)) > 0) {
         $icon .= ' ';
     }
     $label = $icon . ($encodeLabel ? Html::encode($label) : $label);

If I change line 378 in MarkdownEditor.php to if (!is_null($icon) && strlen(trim($icon)) > 0) { everythings works fine again.

Can this be fixed please?

Best regards and thanks for all the smart tools Sarah