Skip to content
This repository was archived by the owner on Nov 5, 2022. It is now read-only.
This repository was archived by the owner on Nov 5, 2022. It is now read-only.

PHP Docs: int/bool vs integer/boolean #22

@natanfelles

Description

@natanfelles

Currently the int params and returns are being updated to integer. Same from bool to boolean.

The following doc (right):

/**
 * @param int $n
 *
 * @return int
 */
public function a(int $n):int
{
	return 2 * $n;
}

is updated to it (wrong):

/**
 * @param integer $n
 *
 * @return integer
 */
public function a(int $n):int
{
	return 2 * $n;
}

The issue is that @return integer is not int (a number)... On returns it must be int because updating to integer we say that we are returning an instance of the class integer... Then the type hint :int would have to be changed to :integer, but the PHP will show a fatal error. Because the correct would be:

/**
 * @param integer $n
 *
 * @return integer
 */
public function a(int $n):integer
{
	return new integer(); // An instanceof integer
}

The same applies to boolean's, while the short syntax is the correct.

See:

Test:

<?php

class Test
{
	public function a(int $n):int
	{
		return 2 * $n;
	}

	/**
	 * [b description]
	 *
	 * @param integer $n
	 *
	 * @return integer
	 */
	public function b(integer $n):integer
	{
		return 2 * $n;
	}
}
$test = new Test;
var_dump($test->a(5));
// int(10)
var_dump($test->b(5));
// PHP Fatal error:  Uncaught TypeError: Argument 1 passed to Test::b() must be an instance of integer, integer given, called in...

The CodeIgniter4 Standard is not updating the method type hint, but the docs. What instructs wrong params and return types.

Detected with PHP Integrator.

captura de tela de 2018-02-14 12-55-33

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions