Skip to content

Commit ec7f890

Browse files
authored
Add returns global class command for PHP (#2273)
This pull request is related to issue #2266, PR #2271, and PR #2272. It implements the "returns global class <user.text>" command in ./lang/php/php.talon. PHP uses [namespaces](https://www.php.net/manual/en/language.namespaces.definition.php) for class, interface, function, and constant definitions. Namespaces use the `\` character to declare subnamespaces, and a global namespace reference can be made by prefixing it with `\`. When a namespace is declared, namespace resolution first checks whether proceeding classes and functions are registered in that namespace. Prefixing them with "\" explicitly declares they use the global space. Simple example: ```php <?php namespace App; function currentDate(): \DateTime { return new \DateTime(); } ``` I believe PHP is almost unique in this behavior, which is why I am submitting this PR to add this command to it instead of the common language features. I couldn't find any evidence that coding languages other than C# have a prefix which can declare that a class reference in a type definition must resolve to the global namespace instead of the current namespace.
1 parent e71eaa3 commit ec7f890

1 file changed

Lines changed: 3 additions & 0 deletions

File tree

lang/php/php.talon

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ settings():
2525

2626
state try: user.insert_snippet_by_name("tryStatement")
2727
state catch: user.insert_snippet_by_name("catchStatement")
28+
returns global class <user.text>:
29+
formatted = user.formatted_text(text, "PUBLIC_CAMEL_CASE")
30+
user.code_insert_return_type("\\" + formatted)
2831

2932
var <phrase> [over]:
3033
insert("$")

0 commit comments

Comments
 (0)