fix() 공개 정적인 메소드

NOTE: This error can *frequently* occur with mismatched character sets and higher-than-ASCII characters. Contributed by Theodore R. Smith of PHP Experts, Inc.
public static fix ( string $brokenSerializedData ) : string
$brokenSerializedData string
리턴 string
예제 #1
0
파일: SerTest.php 프로젝트: jbzoo/utils
 public function testFix()
 {
     $expectedData = array('Normal', 'High-value Char: ' . chr(231) . 'a-va?');
     $brokenSerialization = 'a:2:{i:0;s:6:"Normal";i:1;s:23:"High-value Char: ▒a-va?";}';
     $expectedError = array('errno' => 8, 'errstr' => 'unserialize(): Error at offset 55 of 60 bytes');
     $reportedError = array();
     set_error_handler(function ($errno, $errstr, $errfile, $errline, $errcontext) use(&$reportedError) {
         $reportedError = compact('errno', 'errstr');
     });
     unserialize($brokenSerialization);
     is($expectedError['errno'], $reportedError['errno']);
     // Because HHVM's unserialize() error message does not contain enough info to properly test.
     if (!defined('HHVM_VERSION')) {
         is($expectedError['errstr'], $reportedError['errstr']);
     }
     restore_error_handler();
     $fixedSerialization = Ser::fix($brokenSerialization);
     $unserializedData = unserialize($fixedSerialization);
     is($expectedData[0], $unserializedData[0], 'Did not properly fix the broken serialized data.');
     is(substr($expectedData[1], 0, 10), substr($unserializedData[1], 0, 10), 'Did not properly fix the broken serialized data.');
 }