|
| 1 | +--TEST-- |
| 2 | +Levenshtein suggestion for undefined class, interface and trait lookups |
| 3 | +--FILE-- |
| 4 | +<?php |
| 5 | +// One edit away — should suggest |
| 6 | +try { new ArrayObjekt(); } catch (Error $e) { echo $e::class, ': ', $e->getMessage(), "\n"; } |
| 7 | +try { new StdClas(); } catch (Error $e) { echo $e::class, ': ', $e->getMessage(), "\n"; } |
| 8 | + |
| 9 | +// One edit away for a longer name — should suggest |
| 10 | +try { new ArrayIteratr(); } catch (Error $e) { echo $e::class, ': ', $e->getMessage(), "\n"; } |
| 11 | + |
| 12 | +// Two edits away for a name >= 8 chars — adaptive threshold should suggest |
| 13 | +try { new ArryObjct(); } catch (Error $e) { echo $e::class, ': ', $e->getMessage(), "\n"; } |
| 14 | + |
| 15 | +// Completely wrong name — no suggestion |
| 16 | +try { new Unicorn(); } catch (Error $e) { echo $e::class, ': ', $e->getMessage(), "\n"; } |
| 17 | + |
| 18 | +// Interface |
| 19 | +try { |
| 20 | + $c = new class() implements Countble {}; |
| 21 | +} catch (Error $e) { echo $e::class, ': ', $e->getMessage(), "\n"; } |
| 22 | + |
| 23 | +// Trait |
| 24 | +try { |
| 25 | + eval('class T { use NonExistntTrait; }'); |
| 26 | +} catch (Error $e) { echo $e::class, ': ', $e->getMessage(), "\n"; } |
| 27 | +?> |
| 28 | +--EXPECTF-- |
| 29 | +Error: Class "ArrayObjekt" not found (did you mean ArrayObject?) |
| 30 | +Error: Class "StdClas" not found (did you mean stdClass?) |
| 31 | +Error: Class "ArrayIteratr" not found (did you mean ArrayIterator?) |
| 32 | +Error: Class "ArryObjct" not found (did you mean ArrayObject?) |
| 33 | +Error: Class "Unicorn" not found |
| 34 | +Error: Interface "Countble" not found (did you mean Countable?) |
| 35 | +Error: Trait "NonExistntTrait" not found |
0 commit comments