Skip to content

Added array_last_key() function, returns key of last array item - #131

Closed
hikari-no-yume wants to merge 2 commits into
php:masterfrom
hikari-no-yume:array_last_key
Closed

hikari-no-yume wants to merge 2 commits into
php:masterfrom
hikari-no-yume:array_last_key

Conversation

@hikari-no-yume

Copy link
Copy Markdown
Contributor
  • Added array_last_key to standard extension
  • Added array_last_key test to standard extension tests

Comment thread ext/standard/basic_functions.c Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This arginfo first parameter should be 0 because it's not a referenced parameter.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ninja'd (fixed, rewrote history)

- Added array_last_key to standard extension
- Added array_last_key test to standard extension tests
- Added array_first_key to standard extension
- Added array_first_key test to standard extension tests
Comment thread ext/standard/array.c

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There should be a '$' in parameter name :)

@hikari-no-yume

Copy link
Copy Markdown
Contributor Author

Seems to be little interest, closing.

heyJordanParker added a commit to heyJordanParker/php-sharp that referenced this pull request Oct 13, 2026
Problem:
Master gained php#131 (`count()` on List and Map through `INLINED_COLLECTION_METHODS`) and php#132
(`type_test_of`, the one decision of which types `is` and `as` have a PHP test for). Three
files conflicted. php#132's `type_test_of` treats every `Hint::Identifier` as a class, so on this
branch `value as T` would pass the checker and lower to `instanceof T`, against a class named
`T`: false for every value, a silent wrong answer. The branch also refused type tests of type
arguments with its own `untested_type` rule beside php#132's, and the analyzer had a third,
`erased_type`. R3a's `SHARP_IS_TYPE` and `SHARP_TYPE_OF` lowering, its `tested_types` record
and the two node kinds stayed in the tree although the refusal means no accepted program
reaches them, and the engine never compiled either kind.

Solution:
- `crates/syntax/src/utils/pattern.rs`: master's `type_test_of` and `Shape::type_test`. It now
  takes `is_type_parameter`, so a type parameter has no PHP test. `has_type_test` and
  `php_shape` pass it in, from the names their callers already resolve.
- `crates/semantics/src/internal/checker/sharp.rs`: master's `as` and pattern arms, reading
  `is_tested`, which asks `has_type_test`. `is T`, `as T`, a `match` arm of `T`, and a class
  with type arguments are "This type is not supported yet in PHP#.", as `as List<int>` is on
  master. `untested_type` and `report_erased_test` are deleted. A catch clause of a type
  parameter keeps its refusal through `untested_catch_name`, which asks the same decision.
- `crates/analyzer/src/expression/mod.rs`: `is_untestable` asks `has_type_test` too, and
  `typeof` of a type parameter is refused again. `erased_type` and its syntax test are deleted.
- `crates/sharp-bridge/src/lower.rs`: master's plain property read in a tested null-safe link,
  with this branch's `method_value` signature. R3a's lowering is deleted: `SHARP_IS_TYPE`,
  `SHARP_TYPE_OF`, `Types::tested_type`, the analyzer's `tested_types` record, its narrowing
  and `instanceof` type, `typeof(T)` as `Class<T>`, and the four analyzer tests that narrowed
  to type arguments. R3c restores them from df78eac. The two kinds leave `kind.rs`, and
  `SHARP_UNIT_ABI` is regenerated from php-sharp's `Zend/zend_ast.h` without them.

crates/
├── syntax/src/utils/pattern.rs              <- type_test_of takes is_type_parameter
├── syntax/src/cst/cst/type_hint.rs, mod.rs  <- erased_type deleted
├── syntax/tests/sharp.rs                    <- erased_type's test deleted
├── semantics/src/internal/checker/sharp.rs  <- conflict: master's arms through is_tested
├── semantics/tests/sharp.rs                 <- one refusal test for type arguments
├── analyzer/src/context/assertion.rs        <- passes is_type_parameter
├── analyzer/src/expression/mod.rs           <- is_untestable reads has_type_test
├── analyzer/src/expression/type_of.rs       <- typeof of a class only
├── analyzer/src/expression/binary/mod.rs    <- R3a's instanceof type deleted
├── analyzer/src/assertion.rs, artifacts.rs  <- R3a's tested_types deleted
├── analyzer/src/statement/function_like/mod.rs
├── analyzer/tests/sharp.rs                  <- R3a narrowing tests deleted, refused rows added
├── codex/src/ttype/builder.rs               <- get_class_strings_of crate-private again
└── sharp-bridge/
    ├── src/lower.rs                         <- conflict: master's link read; R3a lowering deleted
    ├── src/lower/types.rs                   <- tested_type deleted
    ├── src/kind.rs                          <- two kinds out, ABI regenerated
    └── tests/lower.rs                       <- is, as, match and typeof of T refused
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants