Skip to content

Bug: Fatal error when no user-agent is available #3029

Description

@mpouyandeh

Describe the bug
If there is no user-agent available, an error will happen.

CodeIgniter 4 version
v4.0.3

Affected module(s)
HTTP\UserAgent

Expected behavior, and steps to reproduce if appropriate
1- Add a method to the Home controller
2- Put var_dump((string)\Config\Services::request()->getUserAgent()); in the method you just created.
3- call that method from the command line(for instance)
4- I expect to see string(0) "" or NULL without seeing any exceptions

The actual result:
PHP Fatal error: Method CodeIgniter\HTTP\UserAgent::__toString() must not throw an exception, caught TypeError: Return value of CodeIgniter\HTTP\UserAgent::getAgentString() must be of the type string, null returned

Context

  • OS: Fedora 31
  • Web server -
  • PHP version 7.3.17

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugVerified issues on the current code behavior or pull requests that will fix them

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions