From bccf9754c7822197d352c798c23eb16764f8115c Mon Sep 17 00:00:00 2001 From: David Snider Date: Tue, 13 Apr 2021 14:58:06 -0700 Subject: [PATCH] Have incrementing empty string log Summary: onthetin Reviewed By: alexeyt Differential Revision: D27743379 fbshipit-source-id: 3c40d1d12bf2c1e24cb27c73b834e97c4dc9917f --- hphp/runtime/base/tv-arith.cpp | 10 ++++++++++ hphp/test/slow/implicit_conversions/incdec/array.php.expectf | 6 +++++- hphp/test/slow/implicit_conversions/incdec/basic.php.expectf | 6 +++++- .../test/slow/implicit_conversions/incdec/literals.php.expectf | 8 ++++++-- hphp/test/slow/implicit_conversions/incdec/prop.php.expectf | 6 +++++- hphp/test/slow/implicit_conversions/incdec/sprop.php.expectf | 6 +++++- 6 files changed, 36 insertions(+), 6 deletions(-) diff --git a/hphp/runtime/base/tv-arith.cpp b/hphp/runtime/base/tv-arith.cpp index 20edd1c9cb2..716de56128c 100644 --- a/hphp/runtime/base/tv-arith.cpp +++ b/hphp/runtime/base/tv-arith.cpp @@ -576,6 +576,16 @@ struct IncBase { } TypedValue emptyString() const { + if (RuntimeOption::EvalNoticeOnCoerceForIncDec > 0) { + const auto level = + flagToConvNoticeLevel(RuntimeOption::EvalNoticeOnCoerceForIncDec); + const auto str = "Increment on empty string"; + if (level == ConvNoticeLevel::Throw) { + SystemLib::throwInvalidOperationExceptionObject(str); + } else if (level == ConvNoticeLevel::Log) { + raise_notice(str); + } + } return make_tv(s_1.get()); } diff --git a/hphp/test/slow/implicit_conversions/incdec/array.php.expectf b/hphp/test/slow/implicit_conversions/incdec/array.php.expectf index fc959b4b93e..17cf02c02fe 100644 --- a/hphp/test/slow/implicit_conversions/incdec/array.php.expectf +++ b/hphp/test/slow/implicit_conversions/incdec/array.php.expectf @@ -25,7 +25,11 @@ foobar> postdec< Notice: Decrement on string 'foobar' in %s/array.php on line 33 foobarfoobar> string(0) "" -preinc<1> postinc<1> predec< +preinc< +Notice: Increment on empty string in %s/array.php on line 26 +1> postinc< +Notice: Increment on empty string in %s/array.php on line 28 +1> predec< Notice: Implicit string to int conversion for pre/post inc/dec in %s/array.php on line 31 -1> postdec< Notice: Implicit string to int conversion for pre/post inc/dec in %s/array.php on line 33 diff --git a/hphp/test/slow/implicit_conversions/incdec/basic.php.expectf b/hphp/test/slow/implicit_conversions/incdec/basic.php.expectf index 9e59e006cef..7a6161f22a5 100644 --- a/hphp/test/slow/implicit_conversions/incdec/basic.php.expectf +++ b/hphp/test/slow/implicit_conversions/incdec/basic.php.expectf @@ -25,7 +25,11 @@ foobar> postdec< Notice: Decrement on string 'foobar' in %s/basic.php on line 35 foobarfoobar> string(0) "" -preinc<1> postinc<1> predec< +preinc< +Notice: Increment on empty string in %s/basic.php on line 25 +1> postinc< +Notice: Increment on empty string in %s/basic.php on line 28 +1> predec< Notice: Implicit string to int conversion for pre/post inc/dec in %s/basic.php on line 32 -1> postdec< Notice: Implicit string to int conversion for pre/post inc/dec in %s/basic.php on line 35 diff --git a/hphp/test/slow/implicit_conversions/incdec/literals.php.expectf b/hphp/test/slow/implicit_conversions/incdec/literals.php.expectf index 1b8ce3fbab2..41a0a0b9a90 100644 --- a/hphp/test/slow/implicit_conversions/incdec/literals.php.expectf +++ b/hphp/test/slow/implicit_conversions/incdec/literals.php.expectf @@ -2,7 +2,9 @@ preinc< Notice: Implicit null to int conversion for pre/post inc/dec in %s/literals.php on line 17 111432.234 Notice: Increment on string 'foobar' in %s/literals.php on line 29 -foobas1 +foobas +Notice: Increment on empty string in %s/literals.php on line 31 +1 Notice: Implicit string to int conversion for pre/post inc/dec in %s/literals.php on line 33 1235 Notice: Implicit string to double conversion for pre/post inc/dec in %s/literals.php on line 35 @@ -11,7 +13,9 @@ postinc< Notice: Implicit null to int conversion for pre/post inc/dec in %s/literals.php on line 46 1110142431.2342.234 Notice: Increment on string 'foobar' in %s/literals.php on line 64 -foobarfoobas1 +foobarfoobas +Notice: Increment on empty string in %s/literals.php on line 67 +1 Notice: Implicit string to int conversion for pre/post inc/dec in %s/literals.php on line 70 12341235 Notice: Implicit string to double conversion for pre/post inc/dec in %s/literals.php on line 73 diff --git a/hphp/test/slow/implicit_conversions/incdec/prop.php.expectf b/hphp/test/slow/implicit_conversions/incdec/prop.php.expectf index aaba343db7d..e4ebb00c42d 100644 --- a/hphp/test/slow/implicit_conversions/incdec/prop.php.expectf +++ b/hphp/test/slow/implicit_conversions/incdec/prop.php.expectf @@ -25,7 +25,11 @@ foobar> postdec< Notice: Decrement on string 'foobar' in %s/prop.php on line 41 foobarfoobar> string(0) "" -preinc<1> postinc<1> predec< +preinc< +Notice: Increment on empty string in %s/prop.php on line 31 +1> postinc< +Notice: Increment on empty string in %s/prop.php on line 34 +1> predec< Notice: Implicit string to int conversion for pre/post inc/dec in %s/prop.php on line 38 -1> postdec< Notice: Implicit string to int conversion for pre/post inc/dec in %s/prop.php on line 41 diff --git a/hphp/test/slow/implicit_conversions/incdec/sprop.php.expectf b/hphp/test/slow/implicit_conversions/incdec/sprop.php.expectf index 8fbde7651bc..858b394d2d1 100644 --- a/hphp/test/slow/implicit_conversions/incdec/sprop.php.expectf +++ b/hphp/test/slow/implicit_conversions/incdec/sprop.php.expectf @@ -25,7 +25,11 @@ foobar> postdec< Notice: Decrement on string 'foobar' in %s/sprop.php on line 40 foobarfoobar> string(0) "" -preinc<1> postinc<1> predec< +preinc< +Notice: Increment on empty string in %s/sprop.php on line 30 +1> postinc< +Notice: Increment on empty string in %s/sprop.php on line 33 +1> predec< Notice: Implicit string to int conversion for pre/post inc/dec in %s/sprop.php on line 37 -1> postdec< Notice: Implicit string to int conversion for pre/post inc/dec in %s/sprop.php on line 40 -- 2.11.4.GIT