Skip to content

The origin intention is to set all the elements to NULL? - #151

Closed
Zimilo wants to merge 1 commit into
php:masterfrom
Zimilo:master
Closed

Zimilo wants to merge 1 commit into
php:masterfrom
Zimilo:master

Conversation

@Zimilo

@Zimilo Zimilo commented Aug 6, 2012

Copy link
Copy Markdown

Error to submit

The origin intention is to set all the elements to NULL?
@Zimilo Zimilo closed this Aug 6, 2012
heyJordanParker added a commit to heyJordanParker/php-sharp that referenced this pull request Oct 13, 2026
Problem

A plain PHP file that called a plain PHP parent's method through a PHP#
subclass was checked against a weaker parameter type than the same
call through the parent. With `Lib\Store::keep` declared as
`/** @PARAM list<int> $rows */ public function keep(array $rows)` and
the PHP# class `Demo\Rows` extending it, `$store->keep(['a' => 'b'])`
reported invalid-argument and `$rows->keep(['a' => 'b'])` reported
nothing. The analyzer chose the PHP declaration over the docblock type
because the receiver's class was PHP#, though the method was plain PHP.

The same decision went the other way through a plain PHP subclass of
a PHP# class: `Coin::op_Equality($coin, null)` reported null-argument,
though `Money::op_Equality($money, null)` takes the null it lifts.

The effect summary of a `new` made the same mistake. `new Rows()` ran
plain PHP `Store::__construct` but was recorded as a PHP# body that
does not exist, so a getter creating it passed with an unknown effect.
`new Coin(5)` ran PHP# `Money`'s constructor but was recorded as plain
PHP with an unknown effect, so a getter creating it was refused.

Solution

The called method decides. A plain PHP caller reads the PHP
declaration only of a method a PHP# file declares, as the literal
rules in `analyze_invocation` already decide by the method's flags.
A `new` decides by the class that declares the constructor, and by the
named class when none declares one. A plain PHP constructor's effect
names the class that declares it, so the help names an `extern` the
project can write.

.php results through a plain PHP class, and through a PHP# class for a
method PHP# declares, are unchanged.

crates/analyzer/
  src/invocation/analyzer.rs    get_parameter_type takes the invocation
                                target and decides by the method's flags
  src/effects/summary.rs        instantiate decides by the constructor's
                                declaring class
  tests/sharp.rs                a_call_is_checked_by_the_class_that_declares_the_member_not_the_class_it_goes_through

Fixes php#151
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.

1 participant