在检查来自单独类的字段值时从父函数返回

<?php
class CustomerLocation{
    public function checkPhone($phone) {
        if(isset($phone) && (strlen($phone) == 10 || strlen($phone) == 12))
        {
            return $phone;
        }
        else
        {
            $aResponse = array(
                "error" => "400",
                "message" => array(
                    "code" => "Invalid_phone",
                    "dev_msg" => "The phone must be at least 10 characters.",
                    "user_msg" => "Please enter valid phone number."
                ),
             );
            return $aResponse;
        }
    }
}

class test {
    public function test()
    {
        $loc = new CustomerLocation();
        $query = array("phone" => $loc->checkPhone('123456'));
        // some more code be executed
    }
}

I want to return from the test function with the response message written in checkPhone method of CustomerLocation class if the phone number does not match the specific condition. But the problem is that I want to check the field of the array which is either by post or request method. How to go about any help will be grateful. Thanks.

Check this,

<?php
class CustomerLocation{
    public function checkPhone($phone = NULL) {
        if(isset($phone) && (strlen($phone) == 10 || strlen($phone) == 12))
        {
            return $phone;
        }
        else
        {
            $aResponse = array(
                "error" => "400",
                "message" => array(
                    "code" => "Invalid_phone",
                    "dev_msg" => "The phone must be at least 10 characters.",
                    "user_msg" => "Please enter valid phone number."
                ),
             );
            return $aResponse;
        }
    }
}

class test {
    public function testnew($phone1)
    {
        $loc = new CustomerLocation();
        $checkphone =  $loc->checkPhone($phone1);
        $error = isset($checkphone['error']) ? $checkphone['error'] : '';
        if($error == 400){
            $query = array("phone" => $checkphone); 
            return $query;
        }
        else{
            // do some thing
        }
    }
}

echo "<pre>";
$test = new test();
$phone1 = '0123456789';//$_POST['phone'];
$output = $test->testnew($phone1);
print_r($output);

May be solve your problem