Search code examples
phpstringreplace

Can native PHP functions be called as class methods?


I am using php 5.4 and str_replace should be a standard function but when I try and use it it errors out on me:

PHP Fatal error: Call to undefined method stdClass::str_replace()

Here is my php.ini: http://www.mediafire.com/view/uuhn9jhcbnohnod/php.ini

Code Snippet:

$id = $decoded->str_replace(" ", "", $origin)->id;

Solution

  • Change this:

    $id = $decoded->str_replace(" ", "", $origin)->id;
    

    to:

    $id = str_replace(" ", "", $origin->id);
    

    Thus str_replace is built-in PHP function, you should call it directly and not as method of any object.