chargebee / chargebee-php

PHP library for the Chargebee API.
https://apidocs.chargebee.com/docs/api?lang=php
MIT License
72 stars 62 forks source link

Magic getter method bug #26

Closed obukhov closed 3 years ago

obukhov commented 5 years ago

In the method \ChargeBee_Model::__get there is a bug affecting snake case fields:

public function __get($k)
    {
        if (isset($this->_data[$k])) 
        {
            return $this->_data[$k];
        } 
        else if(in_array($k, $this->allowed))
        {
            return null;
        }

The property allowed contains snake case fields (i.e. "CustomerBillingAddress" has "first_name"). However "_data" field contains keys already converted to camelCase. See line 131 of the same file:

$this->_data[ChargeBee_Util::toCamelCaseFromUnderscore($k)] = $setVal;

So if the first name in billing address is empty, both $billingAddress->first_name and $billingAddress->firstName throws an error.

Expected result: if the field is empty it should return null

cb-rakesh commented 3 years ago

This has been fixed in v3.0.0