[wp-trac] [WordPress Trac] #62370: Fatal error in convert_smilies() due to count() receiving non-countable value

WordPress Trac noreply at wordpress.org
Sun Nov 10 11:01:10 UTC 2024


#62370: Fatal error in convert_smilies() due to count() receiving non-countable
value
-------------------------------+-------------------------------------
 Reporter:  mcqueen22          |      Owner:  (none)
     Type:  defect (bug)       |     Status:  new
 Priority:  normal             |  Milestone:  Awaiting Review
Component:  Formatting         |    Version:  6.6.2
 Severity:  normal             |   Keywords:  has-patch needs-testing
  Focuses:  php-compatibility  |
-------------------------------+-------------------------------------
 Hi,

 I have identified a recurring error in the convert_smilies() function
 located in the wp-includes/formatting.php file. The error I encountered is
 as follows:

 {{{ Fatal error: Uncaught Error: count(): Argument #1 ($value) must be of
 type Countable|array, false given }}}

 This occurs on line 3495 of the formatting.php file, where the count()
 function attempts to count a value $textarr that may be false. After
 investigating, I discovered that preg_split() in the convert_smilies()
 function returns false under certain circumstances, causing this error.

 I made a modification to prevent this issue by verifying that $textarr is
 an array before calling count(). The modified code is as follows:

 {{{ #!php if ( is_array( $textarr ) ) { $stop = count( $textarr ); } else
 { $stop = 0; } }}}

 This modification ensures that count() only receives a valid value,
 avoiding the fatal error. I would appreciate it if you could review this
 solution and consider including a similar change in a future version of
 WordPress to prevent other users from experiencing this problem.

 My PHP version is 8.3.

 I wait tour news. Thanks

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/62370>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list