Resolving the PHP Type‑Hint Error: Argument 1 Must Be an Instance of int
This article explains a confusing PHP error where a method expects an instance of int but receives an integer, analyzes three common causes—including an incorrect use statement, outdated PHP version, and unnecessary type hint—and provides concise solutions for each.
The article presents a puzzling PHP error: a method expects an instance of int but receives a plain integer, causing a type‑hint failure.
Argument 1 passed to admins\components\Answer::batchSaveItem() must be an instance of admins\components\int, integer given, called in admins/controllers/LibraryController.php on line 256 and defined
First possible cause: At the top of the file a wrong import was added, e.g. use modules\answer\admin\components\int; , which makes PHP treat int as a class name. Removing or correcting the import resolves the issue.
Second possible cause: The PHP runtime is older than 7.0, which does not support scalar type hints like int . Upgrading to PHP 7.0 or newer fixes the error.
Third possible cause: The type hint itself can be removed if strict typing is not required; after deleting the int type declaration the code works again.
Readers are encouraged to leave comments and discuss further solutions.
php中文网 Courses
php中文网's platform for the latest courses and technical articles, helping PHP learners advance quickly.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.