Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeError arg# on \string when passing objects implementing __toString() cast function #42

Closed
scaytrase opened this issue Dec 11, 2015 · 5 comments
Labels
bug A crash in Phan, a recent change causing incorrect analysis results, etc.
Milestone

Comments

@scaytrase
Copy link
Contributor

<?php

class Stringular
{
    public function __toString()
    {
        return 'test string';
    }
}

function test(\string $test)
{
    echo $test;
}

test(new Stringular());
C:\Work\Tools\PHP7\php.exe C:\Work\Tools\phan\sample.php
test string
> C:\Work\Tools\PHP7\php.exe phan sample.php
sample.php:16 TypeError arg#1(test) is \stringular but \test() takes \string defined at sample.php:11
@morria morria added the bug A crash in Phan, a recent change causing incorrect analysis results, etc. label Dec 11, 2015
@morria morria added this to the 1.0 milestone Dec 11, 2015
@rlerdorf
Copy link
Collaborator

Note that \string is not valid. I know it works in PHP-7.0.0 but that was an oversight and will be fixed in 7.0.1
See: https://github.com/php/php-src/blob/PHP-7.0/NEWS#L58-L59

@scaytrase
Copy link
Contributor Author

thank for noting this

@rlerdorf
Copy link
Collaborator

Actually, we need to check if the calling file has strict_types enabled here. This is a type error in strict mode.

@rlerdorf rlerdorf reopened this Dec 12, 2015
@scaytrase
Copy link
Contributor Author

Yes, though to open another bug for this.

rlerdorf added a commit that referenced this issue Dec 12, 2015
Keep track of the strict_types setting for files and start
thinking about the best way to avoid a class with a __toString()
satisfying the string type in strict_types=1 mode
@morria
Copy link
Member

morria commented Dec 15, 2015

I added the issue #71 to cover the remaining parts of this issue.

@morria morria closed this as completed Dec 15, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A crash in Phan, a recent change causing incorrect analysis results, etc.
Projects
None yet
Development

No branches or pull requests

3 participants