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

Ignoring TimecopDateTime during reflection? #5

Open
klaussilveira opened this issue May 12, 2014 · 11 comments
Open

Ignoring TimecopDateTime during reflection? #5

klaussilveira opened this issue May 12, 2014 · 11 comments

Comments

@klaussilveira
Copy link

Take a look at the following snippet:

<?php

class Test
{
    public function setCreatedAt(DateTime $createdAt)
    {
        $this->createdAt = $createdAt;
    }
}

$test = new Test();

$reflection = new ReflectionClass($test);
$params = $reflection->getMethod('setCreatedAt')->getParameters();

foreach ($params as $param) {
    echo $param->getClass()->getName();
}

When using Reflection's API to check the Type Hint of the params of methods, the TimecopDateTime class is found, instead of DateTime itself. How can we avoid this behavior? I'm unable to use the timecop extension since it's conflicting with Doctrine's ProxyGenerator.

@hlegius
Copy link

hlegius commented May 14, 2014

👍 on this.

@shouze
Copy link
Contributor

shouze commented May 28, 2014

@klaussilveira indeed we will face the same issue on our side. We released https://github.com/rezzza/TimeTraveler if it can help you but it's for testing purpose only, not to use in production. AOP extension is leaking and have some bugs too BTW.

@shouze
Copy link
Contributor

shouze commented Jun 11, 2014

@klaussilveira can you plz point in doctrine ProxyGenerator lines where you get such type hinting exception?
https://github.com/doctrine/common/blob/master/lib/Doctrine/Common/Proxy/ProxyGenerator.php

Can you execute this piece of code on your own?

 if (\TimecopDateTime instanceof \DateTime) {
   echo "TimecopDateTime is an instanceof DateTime\n";
 }

@hlegius any clue?

@four43
Copy link

four43 commented Jan 9, 2015

+1, we ran into the same issue. Seems to be around https://github.com/doctrine/common/blob/master/lib/Doctrine/Common/Proxy/ProxyGenerator.php#L941 it's returning the \TimecopDateTime instead of our type hinted \DateTime.

@CristianGiordano
Copy link

I have run into this problem, for me a simple solution was to ask for a DateTimeInterface instead of a particular type.

@veloper
Copy link

veloper commented Apr 21, 2015

+1 on the doctrine proxy generation issue.

The proxy classes are created with method parameter type hints of TimecopDateTime instead of the expected DateTime

@veloper
Copy link

veloper commented May 5, 2015

Bone headed work around after doctrine proxy generation:

sed -i -- 's/TimecopDateTime/DateTime/g' /current/release/proxies/*

@IonBazan
Copy link
Contributor

IonBazan commented Nov 8, 2017

@veloper @klaussilveira Can you confirm the bug is still valid? I can't reproduce it on newest timecop builds.

@veloper
Copy link

veloper commented Nov 9, 2017

@IonBazan - Which pecl version would you like me to test against?

@IonBazan
Copy link
Contributor

Try to compile from master.

@rquadling
Copy link

Is this extension still maintained? It would be nice to get some feedback on some of the issues?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants