如何让一个类函数返回一个整数而不是一个对象?

I want to create a plugin in WordPress, but I beleive that my issue is purely PHP related, so I'm posting here.

Essentially, I want to retrieve a result from a variable that I pass into a function. A super simplified example can be found below:

class my_class {
    public function my_function($my_var){
        return $my_var;
    }

}

$my_class = new my_class();
$var = 10;
$my_function_result = $my_class->my_function($var);
$x = 1; 
while($x <= 5) {
    echo $my_function_result . '<br>';
     $x++;
};

When I have this as just a plain PHP file (i.e. locahost/test/) things work as expected, however, in WordPress, I'm getting a loop like:

int(10) 10
int(10) 10
int(10) 10
int(10) 10
int(10) 10

I'm just starting out with OOP, so I've no idea what's going on. Also, please forgive me if I've mis-titled this or am using the wrong nomenclature.

Can anyone point me into the write direction as to why it's outputting the int(#) first?

Thanks in advance!