Skip to content

Commit 5dc6fa5

Browse files
committed
Add support for @ and magic constants in search (#974)
The manual-lookup search did not consult is_known_term() or is_known_variable(), so searching for operators like @ or magic constants like __LINE__ returned no results. Now these are checked before falling back to the manual page lookup. Also adds all magic constants (__LINE__, __FILE__, __DIR__, etc.) to both $uri_aliases and is_known_term().
1 parent 80d3119 commit 5dc6fa5

3 files changed

Lines changed: 28 additions & 0 deletions

File tree

error.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -457,6 +457,16 @@
457457
"language.oop5.reflection" => "book.reflection", // BC
458458
"::" => "language.oop5.paamayim-nekudotayim",
459459

460+
"__line__" => "language.constants.magic",
461+
"__file__" => "language.constants.magic",
462+
"__dir__" => "language.constants.magic",
463+
"__function__" => "language.constants.magic",
464+
"__class__" => "language.constants.magic",
465+
"__trait__" => "language.constants.magic",
466+
"__method__" => "language.constants.magic",
467+
"__property__" => "language.constants.magic",
468+
"__namespace__" => "language.constants.magic",
469+
460470
"__construct" => "language.oop5.decon",
461471
"__destruct" => "language.oop5.decon",
462472
"__call" => "language.oop5.overloading",

include/errors.inc

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -472,6 +472,16 @@ function is_known_term(string $term): ?string {
472472
'yield from' => 'language.generators.syntax.php#control-structures.yield.from',
473473
'yield' => 'language.generators.syntax.php#control-structures.yield',
474474

475+
'__line__' => 'language.constants.magic.php',
476+
'__file__' => 'language.constants.magic.php',
477+
'__dir__' => 'language.constants.magic.php',
478+
'__function__' => 'language.constants.magic.php',
479+
'__class__' => 'language.constants.magic.php',
480+
'__trait__' => 'language.constants.magic.php',
481+
'__method__' => 'language.constants.magic.php',
482+
'__property__' => 'language.constants.magic.php',
483+
'__namespace__' => 'language.constants.magic.php',
484+
475485
'__COMPILER_HALT_OFFSET__' => 'function.halt-compiler.php',
476486
'DEFAULT_INCLUDE_PATH' => 'reserved.constants.php',
477487
'E_ALL' => 'errorfunc.constants.php',

manual-lookup.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,14 @@
2727
if ($function) {
2828
$function = strtolower($function);
2929

30+
// Check known terms and variables (operators like @, magic constants, etc.)
31+
if ($path = is_known_variable(str_replace('_', '-', $function))) {
32+
mirror_redirect("/manual/$LANG/$path");
33+
}
34+
if ($path = is_known_term($function)) {
35+
mirror_redirect("/manual/$LANG/$path");
36+
}
37+
3038
// Try to find appropriate manual page
3139
if ($file = find_manual_page($LANG, $function)) {
3240
mirror_redirect($file);

0 commit comments

Comments
 (0)