Morgan Forever
Morgan Forever

Reputation: 117

Does anybody in the world knows why this PHP object call is not working?

I'm pretty new on PHP programming. I'm trying to do something not very difficult, nonetheless following VERY BASIC code does not either return an error or displaying any output. Playing around I guess it's related to $this->... line, I can't figure out why calling the function inside the object is not working. Please Help !!!

class TargetBuy {

    public $ClientCode;
    public $Service;
    public $ServiceType; // Emissione, Cambio, Riemissione, Rimborso, NoShow... 
    public $RateType; // tipo tariffa
    public $Segment; // tratta
    public $CityHotel;
    public $TicketType; // one way or round trip
    public $AdvancePurchase;
    public $Penalty;
    public $Taxes; // 0=NotIncluded; 1=Included
    public $FinalPrice;

    function CalculateTB_Price() {  
        $this->ClientCode='Hello';
        echo $ClientCode;
    }

}

$TB = new TargetBuy;

$TB->CalculateTB_Price();

Upvotes: 1

Views: 81

Answers (2)

str
str

Reputation: 45039

$ClientCode is not defined, please enable proper error reporting which would have warned you about that. Instead, you have to use echo $this->ClientCode;.

You should read the basics about object oriented programming.

Upvotes: 3

user1735111
user1735111

Reputation:

because in the last row in the function, you print the var $ClientCode and not the var $this->ClientCode

Upvotes: 3

Related Questions