Exception icon indicating copy to clipboard operation
Exception copied to clipboard

Update README.md

Open panosru opened this issue 7 years ago • 4 comments

Argument 3 passed to Hoa\Exception\Exception::__construct() must be of the type array

panosru avatar Apr 22 '18 12:04 panosru

Hello :-),

If it is not an array, it is automatically casted to an array (for strange backward compatibilities), check https://github.com/hoaproject/Exception/blob/c8dc4f4752182fb8d09ad791244b57d15ced0b3d/Source/Idle.php#L132-L134.

I wonder if we want the user to always pass an array, cc @vonglasow?

Hywan avatar Apr 24 '18 14:04 Hywan

@Hywan Sorry I might have missed your comment!

yes, that is true for \Hoa\Exception\Idle but not for \Hoa\Exception\Exception (at least not for what I have downloaded with composer require hoa/exception

That is mine exception/Source/Exception.php

/**
 * Each exception must extend `Hoa\Exception\Exception`.
 */
class Exception extends Idle implements Event\Source
{
    /**
     * Allocates a new exception.
     *
     * An exception is built with a formatted message, a code (an ID), and an
     * array that contains the list of formatted string for the message. If
     * chaining, a previous exception can be added.
     */
    public function __construct(
        string $message,
        int $code            = 0,
        array $arguments     = [],
        \Throwable $previous = null
    ) {

notice the array $arguments = [], type hinting.

but apparently you have already fallen into the same issue I have now with Fatal error: Uncaught TypeError: Argument 3 passed to Hoa\Exception\Exception::__construct() must be of the type array, string given and you removed the type hinting from \Hoa\Exception\Exception::__construct()

https://github.com/hoaproject/Exception/blob/c8dc4f4752182fb8d09ad791244b57d15ced0b3d/Source/Exception.php#L56-L61

Thankfully I noticed your reply because I was about to make a PR in hoa/event and surround with [] all third params of Exception in hoa/event 😆

Nice work by the way! I'm using both hoa/exception and hoa/event in my omegad-biz/fault-manager lib which so far is under dev :)

panosru avatar Apr 27 '18 08:04 panosru

Just in case anyone falls into the same issue as I did, check your composer.json file because you might either have "minimum-stability": "stable" or "prefer-stable": true.

also after your modifications in composer.json, composer update hoa/exception won't work, you'll need to run composer remove hoa/exception and then composer require hoa/exception in order to get the latest code :)

panosru avatar Apr 27 '18 09:04 panosru

You're right, this is a bug in the master!

Hywan avatar May 16 '18 11:05 Hywan