Skip to content

T of object not working #5643

@diloabininyeri

Description

@diloabininyeri

1/1 [▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓] 100%


Line index.php


54 Call to an undefined method object::getVersion().


[ERROR] Found 1 error

<?php


class ForExample
{
    public function getVersion():string
    {
        return "v.1.2.3";
    }
}

/**
 * @template T of string|int
 * @template  K of object
 */
class Arraylist
{
    /**
     * @var array<T,K>
     */
    private array $arrayList = [];
    /**
     * @param T $key
     * @param K $object
     */
    public function put(int|string $key, object $object): void
    {
        $this->arrayList[$key] = $object;
    }

    /**
     * @param T $key
     * @return  K
     */
    public function get(int|string $key):object
    {
        return $this->arrayList[$key];
    }

    /**
     * @return array<T,K>
     */
    public function getArrayList(): array
    {
        return $this->arrayList;
    }
}


$arrayList = new Arraylist();

$arrayList->put(0,  new ForExample());

echo $arrayList->get(0)->getVersion();

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions