O
O
Orbb2017-01-03 17:20:12
PHP
Orbb, 2017-01-03 17:20:12

Where is the variable overwritten?

Hello.
There is this code:

case 'order':
        $orderObj = new orderHandler($first_name, $last_name, $phone, $adress, $email, $message, $order);
        $msg = "Имя: {$orderObj->getFirstName()} <br>";
        $msg .= "Телефон: {$orderObj->getPhone()} <br>";
        $msg .= "Заказ: {$orderObj->getOrder(false)} <br>";
        $msg .= "Адрес: {$orderObj->getAdress()} <br>";
        break;
}

$arOrder = [
    'order' => $orderObj->getOrder(false),
];

And there is a method:
public function getOrder($toString){
            $order_string = $this->order;
        if($toString){
            $ar = array();
            foreach($order_string as $item){
                if($item == ''){
                    unset($item);
                }
                else{
                    $ar[] = $item;
                }
            }
            $order_string = implode(',', $ar);
            return $order_string;
        }else{
            return $this->order;
        }

    }

The bottom line is this: if I call the $orderObj->getOrder(false) method once, then everything works as it should - at the output I have either a cleaned array or a string, as many times as I like.
But it's worth calling somewhere else, so the mess begins - then the notice will come out that I'm trying to translate the array into a string, then vice versa.
Actually, in any case, you will need 2 outputs - one for the message, and the other for sending to the order processing panel, poke my nose into what I'm doing wrong
ps I introduced a bunch of variables in the method, I thought that I was overwriting it by directly accessing the property, but what - didn't work

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
Maxim Timofeev, 2017-01-03
@webinar

You have an orderHandler object in it, apparently (you did not provide the code of the entire class) there is a public variable order. On the first call it is an array, on the second it is a string. What is there specifically - xs. Give the whole code, or create a new instance of the object each time you access it.

T
ThunderCat, 2017-01-03
@ThunderCat

VAR_DUMP in your hands and go ahead, in this section of the code a lot of things happen "behind the scenes", until you find out where the value has changed, pointing your finger in different directions is useless.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question