Php 对象字符串中的数组合并错误

Php 对象字符串中的数组合并错误,php,arrays,array-merge,Php,Arrays,Array Merge,这里有数组合并错误吗 e->gerMessage()的结果是字符串,我将其放入一个数组中,然后合并它,但我得到的错误是它不是数组 我尝试了var_dump和print_r,但没有注意到任何变化 这是一个密码 if(isset($_POST['submit'])) { var_dump($_FILES); try { // Undefined | Multiple Files | $_FILES Corruption Attack // If this request

这里有数组合并错误吗

e->gerMessage()的结果是字符串,我将其放入一个数组中,然后合并它,但我得到的错误是它不是数组

我尝试了var_dump和print_r,但没有注意到任何变化

这是一个密码

 if(isset($_POST['submit'])) {
    var_dump($_FILES);
try {

    // Undefined | Multiple Files | $_FILES Corruption Attack
    // If this request falls under any of them, treat it invalid.
    if (
        !isset($_FILES['upfile']['error']) ||
        is_array($_FILES['upfile']['error'])
    ) {
        throw new RuntimeException('Invalid parameters.');
    }

    // Check $_FILES['upfile']['error'] value.
    switch ($_FILES['upfile']['error']) {
        case UPLOAD_ERR_OK:
            break;
        case UPLOAD_ERR_NO_FILE:
            throw new RuntimeException('No file sent.');
        case UPLOAD_ERR_INI_SIZE:
        case UPLOAD_ERR_FORM_SIZE:
            throw new RuntimeException('Exceeded filesize limit.');
        default:
            throw new RuntimeException('Unknown errors.');
    }

    // You should also check filesize here. 
    if ($_FILES['upfile']['size'] > 1000000) {
        throw new RuntimeException('Exceeded filesize limit.');
    }

    // DO NOT TRUST $_FILES['upfile']['mime'] VALUE !!
    // Check MIME Type by yourself.
    $finfo = new finfo(FILEINFO_MIME_TYPE);
    if (false === $ext = array_search(
        $finfo->file($_FILES['upfile']['tmp_name']),
        array(
            'jpg' => 'image/jpeg',
            'png' => 'image/png',
            'gif' => 'image/gif',
        ),
        true
    )) {
        throw new RuntimeException('Invalid file format.');
    }

    // You should name it uniquely.
    // DO NOT USE $_FILES['upfile']['name'] WITHOUT ANY VALIDATION !!
    // On this example, obtain safe unique name from its binary data.
    if (!move_uploaded_file(
        $_FILES['upfile']['tmp_name'],
        sprintf('./uploads/%s.%s',
            sha1_file($_FILES['upfile']['tmp_name']),
            $ext
        )
    )) {
        throw new RuntimeException('Failed to move uploaded file.');
    }

    echo 'File is uploaded successfully.';

} catch (RuntimeException $e) {
    $errors_array =  array("error"=>"oh dear");
    $errors["errors"] = $e->getMessage();
    $moh =  array_merge($errors_array , $errors) ;
    echo "--->";

}

如错误所示,$e->getMessage();不是数组,而是字符串,只需添加它

$errors_array =  array("error"=>"oh dear");
$errors_array["error_message"] = $e->getMessage();
$moh =  array_merge($errors_array , $errors) ;
echo "--->";