Call to undefined function doIt ()

class Ball{
    const SHAPE = "circular";
    public $area = null;
}

class Football extends Ball{
    const PI = 3.14;
    public $radius;

    public function __construct($radius){
        $this->radius = $radius;
    }

    public function doIt(){
        $this->area = PI*pow($this->radius,2);
        return "the shape of the ball is:".self::SHAPE."the area is:".$this->area;
    }
}

$fb = new Football(2.15);
echo $fb.doIt();

detailed code as above, there is no problem with writing the code, but it just can"t be executed, indicating that Call to undefined function doIt (), doesn"t know what"s going on.

Php
Mar.03,2021

the method call of the php instantiation class is indicated by->. The writing of $fb.doIt (); cannot specify the corresponding method, and will separate the class from the method: $fb is an object, because it is echo here, so the magic method _ _ toString (), will be called first, and then the later doIt () is recognized as a function, and there is no function defined here, so it will prompt Call to undefined function doIt ().
otherwise you try to define the _ _ toString () magic method in the class and define a function outside the class. The function name is doIt (), and $fb.doIt () is equivalent to getting a string. Good luck~


$fb- > doIt ();


amount. Ask the great god for an explanation. Can you call the method name like $fb.doIt () as mentioned in the question?


Hello, there are two methods of calling a class in php
1) $obj- > function ()
2) $obj::function () this should be defined as a static method

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b3c318-2c2e9.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b3c318-2c2e9.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?