Skip to content

Converting warnings to exceptions in array related functions. #4566

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

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
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
8 changes: 5 additions & 3 deletions Zend/tests/generators/errors/count_error.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@ try {
count($gen);
} catch (Exception $e) {
echo $e;
}
} catch (\TypeError $e) {
echo $e->getMessage() . "\n";
}

?>
--EXPECTF--
Warning: count(): Parameter must be an array or an object that implements Countable in %s on line %d
--EXPECT--
Parameter must be an array or an object that implements Countable
2 changes: 1 addition & 1 deletion Zend/zend_vm_def.h
Original file line number Diff line number Diff line change
Expand Up @@ -8616,7 +8616,7 @@ ZEND_VM_COLD_CONST_HANDLER(190, ZEND_COUNT, CONST|TMPVAR|CV, UNUSED)
} else {
count = 1;
}
zend_error(E_WARNING, "%s(): Parameter must be an array or an object that implements Countable", opline->extended_value ? "sizeof" : "count");
zend_type_error("Parameter must be an array or an object that implements Countable");
break;
}

Expand Down
6 changes: 3 additions & 3 deletions Zend/zend_vm_execute.h
Original file line number Diff line number Diff line change
Expand Up @@ -9558,7 +9558,7 @@ static ZEND_VM_COLD ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_COUNT_SPEC_CONST_
} else {
count = 1;
}
zend_error(E_WARNING, "%s(): Parameter must be an array or an object that implements Countable", opline->extended_value ? "sizeof" : "count");
zend_type_error("Parameter must be an array or an object that implements Countable");
break;
}

Expand Down Expand Up @@ -16687,7 +16687,7 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_COUNT_SPEC_TMPVAR_UNUSED_HANDL
} else {
count = 1;
}
zend_error(E_WARNING, "%s(): Parameter must be an array or an object that implements Countable", opline->extended_value ? "sizeof" : "count");
zend_type_error("Parameter must be an array or an object that implements Countable");
break;
}

Expand Down Expand Up @@ -47323,7 +47323,7 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_COUNT_SPEC_CV_UNUSED_HANDLER(Z
} else {
count = 1;
}
zend_error(E_WARNING, "%s(): Parameter must be an array or an object that implements Countable", opline->extended_value ? "sizeof" : "count");
zend_type_error("Parameter must be an array or an object that implements Countable");
break;
}

Expand Down
4 changes: 2 additions & 2 deletions ext/ffi/tests/008.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ foreach ($a as $key => $val) {

$a = FFI::new("struct {int x,y;}");
try {
var_dump(@count($a));
var_dump(count($a));
} catch (Throwable $e) {
echo get_class($e) . ": " . $e->getMessage()."\n";
}
Expand All @@ -34,5 +34,5 @@ int(3)
0 => 0
1 => 10
2 => 20
FFI\Exception: Attempt to count() on non C array
TypeError: Parameter must be an array or an object that implements Countable
FFI\Exception: Attempt to iterate on non C array
Loading