Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Type Hints causing 4096 error
  • Hi, when using type hints, regardless of what type of param I send, I get an error telling me that the types don't match even if they do. Here is an example:

    Fuel\Core\PhpErrorException [ 4096 ]: Argument 1 passed to
    Service\Service::createRequest() must be an instance of string, instance of string given...

    public static function createRequest(
             string $url
    )
    {}
  • Can you show me the code throwing this error? Thanks
  • Thanks for the quick response. Here is the index controller from the "welcome" action of the fuel sample app. I added a simple foo() private function and simply call it.  Below is the code and below that is the response









    4096!

    Fuel\Core\PhpErrorException [ 4096 ]: Argument 1 passed to Controller_Welcome::_foo() must be an instance of string, string given, called in /usr/local/zend/apache2/htdocs/fuel-sample-app/fuel/app/classes/controller/welcome.php on line 33 and defined

    APPPATH/classes/controller/welcome.php @ line 60


  • Please, no code pastes here, use http://bin.fuelphp.com for that (and post the link instead).

    Your problem is that you can't typehint "string". So PHP assumes it's a class name, and if you pass a string, it's not an instance of a class called "string".

    Which causes this error.
  • Sorry about that. I was surprised at how it formatted that code anyway...
    So PHP does allow type hinting strings. Why does Fuel override that?
  • HarroHarro
    Accepted Answer
    PHP does not support scalar typehints. so "string" is not a valid typehint. Fuel doesn't do anything.

    If you write

    function blah(string $string)

    it will will typehint against a class called "string", not the scalar value "string".

    That's why the error is: Argument 1 passed to Controller_Welcome::_foo() must be an instance of string, string given

    note "instance of string", which indicates an object.
  • Gotcha. We had created a string object in a previous project so I remembered this wrong. Thanks for clearing this up!

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion