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

[PHP7.4] DelegateJoinSelector # select で return $f($v0, $v1, $k0, $k1); できない場合がある #69

Closed
sogaoh opened this issue Dec 10, 2020 · 8 comments

Comments

@sogaoh
Copy link
Contributor

sogaoh commented Dec 10, 2020

PHP 7.4.13 の環境にて
https://zenn.dev/sogaoh/scraps/0898c2ef617dcf のような経緯でデバッグを行っているのですが、
題名の通りの問題が発生してしまっています。

すべては書けないのですが、渡ってきているデータは以下のようなものです

$v0, $v1, $k0, $k1 の var_dump
array(1) {
  ["v0"]=>
  array(22) {
    ["i_type"]=>
    int(1)
    ["reason"]=>
    string(1) "f"
    ["fk_m_id"]=>
    int(1)
    ["fk_p_id"]=>
    int(1)
    ["b_type"]=>
    int(2)
    ["b_date"]=>
    string(19) "2019-12-09 00:00:00"
    ["b_end_date"]=>
    string(19) "2019-12-09 00:00:00"
    ["net"]=>
    int(10000)
    ["gross"]=>
    int(100000)
    ["remarks"]=>
    string(1) "t"
    ["user_type"]=>
    int(1)
    ["created_at"]=>
    object(Illuminate\Support\Carbon)#4192 (16) {
        //略
    }
    ["updated_at"]=>
    object(Illuminate\Support\Carbon)#4196 (16) {
        //略
    }
    ["id"]=>
    int(1)
    ["array_p"]=>
    array(12) {
      //int 8項目
      //string 4項目
    }
    ["array_a"]=>
    array(12) {
      //int 8項目
      //string 4項目
    }
    //その他、いくつか "array_p" や "array_a" のような連想配列
  }
}

array(1) {
  ["v1"]=>
  array(12) {
    ["id"]=>
    int(1)
    ["fk_a_id"]=>
    int(1)
    ["fk_c_id"]=>
    int(1)
    ["name"]=>
    string(17) "Isabella McKenzie"
    ["fk_g_id"]=>
    int(1)
    ["fk_ct_id"]=>
    int(1)
    ["c_p"]=>
    string(12) "xxxxxxxxxxxx"
    ["r_c_type"]=>
    int(0)
    ["user_type"]=>
    int(3)
    ["user_id"]=>
    int(1)
    ["created_at"]=>
    string(19) "2020-12-10 20:40:58"
    ["updated_at"]=>
    string(19) "2020-12-10 20:40:58"
  }
}

array(1) {
  ["k0"]=>
  int(0)
}

array(1) {
  ["k1"]=>
  int(0)
}

「落ちる」のは↓だと思っています。
https://github.com/akanehara/ginq/blob/master/src/Ginq/JoinSelector/DelegateJoinSelector.php#L46

解決方法を考えたいです。

@gunjiro
Copy link
Contributor

gunjiro commented Dec 10, 2020

エラーが原因で止まってしまう、ということでしょうか?

どのようなGinqの呼び出しで問題が発生するか、1つ例を挙げていただくことはできますか?

@gunjiro
Copy link
Contributor

gunjiro commented Dec 12, 2020

少し調べてみました。

テストを実行するとエラーが出るみたいですね。

1) GinqTest::testGroupJoin
Trying to access array offset on value of type null

そしてエラーが発生しているのがここです。

return array($person['name'], $phone['phone']);

よく読んでいただければ分かると思いますが、$phonenullが入るタイミングがあります。
(正確にはもっと前の$person['phones']nullになっている)

そして下位互換性のない変更点で次のように説明されています。

配列でない値を配列スタイルでアクセスした場合
null, bool, int, float または resource 型を ($null["key"] のように) 配列としてアクセスしようとすると、警告が生成されるようになりました。

https://www.php.net/manual/ja/migration74.incompatible.php#migration74.incompatible.core.non-array-access

おそらくこれが原因ではないかと。

@sogaoh
Copy link
Contributor Author

sogaoh commented Dec 12, 2020

調査ありがとうございます。おそらくその「下位互換性のない変更」のようには思っていました。。
対策が今のところ浮かばないです。浮かんだら試してみたいと思います。

@gunjiro
Copy link
Contributor

gunjiro commented Dec 13, 2020

なかなか複雑な操作をすることもありますからね…

Ginq本体を修正しなければいけない可能性も十分にあるので、呼び出し側コードとエラーメッセージ、スタックトレースをフィードバックしていただけると助かります。

@sogaoh
Copy link
Contributor Author

sogaoh commented Dec 13, 2020

コメントありがとうございます。明日採取してお送りしたいと思います。
個別にご連絡する必要があるかもしれず、可能であればSNSアカウントを教えていただけないでしょうか。
(自分は https://twitter.com/sogaoh です)

@gunjiro
Copy link
Contributor

gunjiro commented Dec 13, 2020

ご協力ありがとうございます。

私のアカウントは https://twitter.com/gunjiro_ です。

@sogaoh
Copy link
Contributor Author

sogaoh commented Dec 14, 2020

@gunjiro https://github.com/ant-in-giant/ginq/tree/docker-dev のコードで、

docker-compose up -d
docker-compose exec php ash 
/work # composer install 
/work # vendor/bin/phpunit

して動くようになっているので、適宜ご利用ください。

@sogaoh
Copy link
Contributor Author

sogaoh commented Dec 15, 2020

現象が再現するコードを、ある程度公開可能な状態にしてお渡しして調査していただいた結果、
アプリケーション側のコードに NULL に対して安全になっていない箇所があると特定いただきました。

そのため、本件アプリケーション側を修正します。
調査いただき、本当にありがとうございました。お手数おかけしてしまい申し訳なくも思っています。

代わりになるか、自信がないのですが、PHP と PHPUnit のバージョンアップ対応を行っておいて、
今後のメンテナンスに少し寄与できればと思います。少々お時間ください。

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

No branches or pull requests

2 participants