1--TEST-- 2Bug #51866 (Lenient parsing with parseFromFormat) 3--FILE-- 4<?php 5date_default_timezone_set('UTC'); 6 7$tests = array( 8 array( 'Y-m-d', '2001-11-29 13:20:01' ), 9 array( 'Y-m-d+', '2001-11-29 13:20:01' ), 10 array( 'Y-m-d +', '2001-11-29 13:20:01' ), 11 array( 'Y-m-d+', '2001-11-29' ), 12 array( 'Y-m-d +', '2001-11-29' ), 13 array( 'Y-m-d +', '2001-11-29 ' ), 14); 15foreach( $tests as $test ) 16{ 17 list($format, $str) = $test; 18 var_dump($format, $str); 19 $d = DateTime::createFromFormat($format, $str); 20 var_dump($d); 21 var_dump(DateTime::getLastErrors()); 22 23 echo "\n\n"; 24} 25?> 26--EXPECTF-- 27string(5) "Y-m-d" 28string(19) "2001-11-29 13:20:01" 29bool(false) 30array(4) { 31 ["warning_count"]=> 32 int(0) 33 ["warnings"]=> 34 array(0) { 35 } 36 ["error_count"]=> 37 int(1) 38 ["errors"]=> 39 array(1) { 40 [10]=> 41 string(13) "Trailing data" 42 } 43} 44 45 46string(6) "Y-m-d+" 47string(19) "2001-11-29 13:20:01" 48object(DateTime)#%d (3) { 49 ["date"]=> 50 string(26) "2001-11-29 %d:%d:%d.%d" 51 ["timezone_type"]=> 52 int(3) 53 ["timezone"]=> 54 string(%d) "%s" 55} 56array(4) { 57 ["warning_count"]=> 58 int(1) 59 ["warnings"]=> 60 array(1) { 61 [10]=> 62 string(13) "Trailing data" 63 } 64 ["error_count"]=> 65 int(0) 66 ["errors"]=> 67 array(0) { 68 } 69} 70 71 72string(7) "Y-m-d +" 73string(19) "2001-11-29 13:20:01" 74object(DateTime)#%d (3) { 75 ["date"]=> 76 string(26) "2001-11-29 %d:%d:%d.%d" 77 ["timezone_type"]=> 78 int(3) 79 ["timezone"]=> 80 string(%d) "%s" 81} 82array(4) { 83 ["warning_count"]=> 84 int(1) 85 ["warnings"]=> 86 array(1) { 87 [11]=> 88 string(13) "Trailing data" 89 } 90 ["error_count"]=> 91 int(0) 92 ["errors"]=> 93 array(0) { 94 } 95} 96 97 98string(6) "Y-m-d+" 99string(10) "2001-11-29" 100object(DateTime)#%d (3) { 101 ["date"]=> 102 string(26) "2001-11-29 %d:%d:%d.%d" 103 ["timezone_type"]=> 104 int(3) 105 ["timezone"]=> 106 string(%d) "%s" 107} 108bool(false) 109 110 111string(7) "Y-m-d +" 112string(10) "2001-11-29" 113bool(false) 114array(4) { 115 ["warning_count"]=> 116 int(0) 117 ["warnings"]=> 118 array(0) { 119 } 120 ["error_count"]=> 121 int(1) 122 ["errors"]=> 123 array(1) { 124 [10]=> 125 string(%d) "Not enough data available to satisfy format" 126 } 127} 128 129 130string(7) "Y-m-d +" 131string(11) "2001-11-29 " 132object(DateTime)#%d (3) { 133 ["date"]=> 134 string(26) "2001-11-29 %d:%d:%d.%d" 135 ["timezone_type"]=> 136 int(3) 137 ["timezone"]=> 138 string(%d) "%s" 139} 140bool(false) 141