Skip to content
New issue

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

Update gleam-for-php-users.md #388

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions cheatsheets/gleam-for-php-users.md
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,7 @@ can be invoked from browser's JavaScript, Deno or NodeJS runtime calls.
Type hints can be used to optionally annotate function arguments and return
types.

//TODO check if runtime won't prevent, I think new versions do that
Discrepancies between type hints and actual values at runtime do not prevent
interpretation of the code. Static code analysers (IDE tooling, type checkers
like `phpstan`) will be required to detect those errors.
Expand Down Expand Up @@ -407,7 +408,8 @@ fn mul(x: Int, y: Int) -> Bool {
As long as functions are in scope they can be assigned to a new variable.
As methods or static functions classes, functions can be accessed via
`$this->object_instance_method()` or `self::static_class_function()`.

//TODO update this, with callable syntax since 8.1 other functions can be moved around
// see https://www.php.net/manual/en/functions.first_class_callable_syntax.php
Other than that only anonymous functions can be moved around the same way as
other values.

Expand All @@ -417,6 +419,7 @@ $doubleFn = function($x) { return $x + $x; };
pushFunction($queue, $doubleFn);
```

//TODO update as above
However in `PHP` it is not possible to pass around global, class or instance
functions as values.

Expand Down Expand Up @@ -1419,7 +1422,7 @@ To iterate a few foundational differences:
library.

### Guarantees and types

//TODO check and possibly update this
- PHP features opt-in static typing which is only checked at runtime.
- PHP values tend to be automatically cast for comparison purposes or when used
as indexes in arrays. Gleam values are not automatically cast.
Expand Down