If! empty operator resets my site

I have the following if statment:

<a href="#"
   title="<?php the_sub_field('points_description'); ?>"
   class="<?php if(!empty(the_sub_field('points_description'))) {
                  echo 'point-tooltip'; } ?>">

If I just include the echo part that the site shows, but when I add the if part (checking if there is a function ""), the site just displays blank.

Any suggestions for fixing this issue?

+3
source share
2 answers

An empty function only works with vars.

empty () only checks for variables since everything else will result in a parsing error. In other words, the following will not work: empty (trim ($ name)).

+6
source

empty () only works with variables, as this function also checks if a function is defined.

To make the code below the executable

// doesn't work :(
if(!empty(a_function($var)))
    do_stuff();

you need to save the result from a_function () to a temporary variable

//works :D
$temp = a_function($var);
if(!empty($temp))
    do_stuff();
-2
source

All Articles