We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
// Declaration class Vector<T> { public function add(T $t): self { ... } public function get(int $i): T { ... } } // Instantiation $vector= new Vector<string>();
xp-framework/rfc#106 xp-framework/rfc#193 https://wiki.php.net/rfc/generics https://docs.hhvm.com/hack/generics/introduction
The text was updated successfully, but these errors were encountered:
Real-life example:
diff --git a/src/main/php/de/thekid/dialog/color/PriorityQueue.php b/src/main/php/de/thekid/dialog/color/PriorityQueue.php index a683a76..6fcb295 100755 --- a/src/main/php/de/thekid/dialog/color/PriorityQueue.php +++ b/src/main/php/de/thekid/dialog/color/PriorityQueue.php @@ -1,12 +1,12 @@ <?php namespace de\thekid\dialog\color; /** @test de.thekid.dialog.unittest.PriorityQueueTest */ -class PriorityQueue { +class PriorityQueue<T> { private $elements= []; private $sorted= true; private $comparator= null; - public function comparing(function(mixed, mixed): int $comparator): self { + public function comparing(function(T, T): int $comparator): self { $this->comparator= $comparator; return $this; } @@ -17,13 +17,13 @@ class PriorityQueue { } /** Pushes an element */ - public function push($element): void { + public function push(T $element): void { $this->elements[]= $element; $this->sorted= false; } /** Pops an element */ - public function pop() { + public function pop(): ?T { if (!$this->sorted) { $this->comparator ? usort($this->elements, $this->comparator) : sort($this->elements); $this->sorted= true;
Maybe as an addition xp-lang/xp-generics package?
xp-lang/xp-generics
Sorry, something went wrong.
Yes 😄 -> https://github.com/xp-lang/xp-generics/releases/tag/v0.4.0
No branches or pull requests
Example
See also
xp-framework/rfc#106
xp-framework/rfc#193
https://wiki.php.net/rfc/generics
https://docs.hhvm.com/hack/generics/introduction
The text was updated successfully, but these errors were encountered: