gettype

Supported Versions: PHP 4, PHP 5, PHP 7, PHP 8
Get the type of a variable
<?php gettype(mixed $value): string
<?php             if (! is_array($result)) {

                throw new UnexpectedValueException(sprintf(

                    "%s::reduceSpread expects reducer to return an array, but got a '%s' instead.",

                    class_basename(static::class), gettype($result)

                ));

            }

        }
<?php         if (! is_string($value)) {

            throw new InvalidArgumentException(

                sprintf('Configuration value for key [%s] must be a string, %s given.', $key, gettype($value))

            );

        }
<?php         if (! is_int($value)) {

            throw new InvalidArgumentException(

                sprintf('Configuration value for key [%s] must be an integer, %s given.', $key, gettype($value))

            );

        }
<?php         if (! is_float($value)) {

            throw new InvalidArgumentException(

                sprintf('Configuration value for key [%s] must be a float, %s given.', $key, gettype($value))

            );

        }
<?php         if (! is_bool($value)) {

            throw new InvalidArgumentException(

                sprintf('Configuration value for key [%s] must be a boolean, %s given.', $key, gettype($value))

            );

        }
<?php         if (! is_array($value)) {

            throw new InvalidArgumentException(

                sprintf('Configuration value for key [%s] must be an array, %s given.', $key, gettype($value))

            );

        }
<?php         }



        PHPUnit::assertContains(

            strtolower(gettype($actual)),

            $expected,

            sprintf('Property [%s] is not of expected type [%s].', $this->dotPath($key), implode('|', $expected))

        );
<?php     protected function isSameType($first, $second)

    {

        return gettype($first) == gettype($second);

    }
<?php         $changes = $user->articles()->sync($articleIDs);



        collect($changes['attached'])->map(function ($id) {

            $this->assertSame(gettype($id), (new BelongsToManySyncTestTestArticle)->getKeyType());

        });



        $user->articles->each(function (BelongsToManySyncTestTestArticle $article) {
<?php         $changes = $user->articles()->syncWithPivotValues($articleIDs, ['visible' => true]);



        collect($changes['attached'])->each(function ($id) {

            $this->assertSame(gettype($id), (new BelongsToManySyncTestTestArticle)->getKeyType());

        });



        $user->articles->each(function (BelongsToManySyncTestTestArticle $article) {
<?php         $data = $collection::make([new stdClass, new stdClass, new stdClass, $collection]);

        $this->expectException(UnexpectedValueException::class);

        $this->expectExceptionMessage(sprintf('Collection should only include [%s] items, but \'%s\' found at position %d.', class_basename(new stdClass()), gettype($collection), 3));

        $data->ensure(stdClass::class);

    }
<?php         foreach ([1, 1.1, 'phpinfo', new stdClass] as $condition) {

            try {

                new ExcludeIf($condition);

                $this->fail('The ExcludeIf constructor must not accept '.gettype($condition));

            } catch (InvalidArgumentException $exception) {

                $this->assertEquals('The provided condition must be a callable or boolean.', $exception->getMessage());

            }
<?php         foreach ([1, 1.1, 'phpinfo', new stdClass] as $condition) {

            try {

                new ProhibitedIf($condition);

                $this->fail('The ProhibitedIf constructor must not accept '.gettype($condition));

            } catch (InvalidArgumentException $exception) {

                $this->assertEquals('The provided condition must be a callable or boolean.', $exception->getMessage());

            }
<?php                 throw new BadMethodCallException(sprintf(

                    'Method "%s" does not exist in %s.',

                    $method,

                    gettype($this->value)

                ));

            }
<?php             sprintf(

                "Option 'platform' must be an object and subtype of '%s'. Got '%s'",

                AbstractPlatform::class,

                gettype($invalidPlatform)

            )

        );

    }