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

HHVM compatibility: implement declared interfaces #373

Merged
merged 3 commits into from
Dec 13, 2013

Conversation

javer
Copy link
Contributor

@javer javer commented Sep 15, 2013

HHVM does not allow declaration of interface implementation without real implementation of methods which parameters differs from parent class.

HHVM does not allow declaration of interface implementation without
real implementation of methods which parameters differs from parent
class.
@doctrinebot
Copy link

Hello,

thank you for creating this pull request. I have automatically opened an issue
on our Jira Bug Tracker for you. See the issue link:

http://www.doctrine-project.org/jira/browse/DBAL-609

We use Jira to track the state of pull requests and the versions they got
included in.

@Ocramius
Copy link
Member

@javer are there any breakages in PDO versions that may cause trouble with this?

*/
public function query()
{
$args = func_get_args();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't you just declare a first param on the method and pass it to the parent call?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@staabm, no, because query method in implemented interface Connection declared without parameters and HHVM throws fatal error:

HipHop Fatal error: Declaration of Doctrine\\DBAL\\Driver\\PDOConnection::query() must be compatible with that of Doctrine\\DBAL\\Driver\\Connection::query() in /path/to/doctrine/dbal/lib/Doctrine/DBAL/Driver/PDOConnection.php on line 30

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So the interface should be adjusted?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@staabm interface changes in 2.x are denied

@javer
Copy link
Contributor Author

javer commented Sep 16, 2013

Connection interface is not compatible with declaration of native PDO class, and I don't know, why is this works in PHP. But HHVM checks implementation more strict and we should find a solution compatible both with PHP and HHVM. Same issues are with interfaces Statement and ResultStatement combining with class PDOStatement.

/**
* {@inheritdoc}
*/
public function quote($input, $type=\PDO::PARAM_STR)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missing spaces

@stof
Copy link
Member

stof commented Sep 16, 2013

this seems to break the tests

@javer
Copy link
Contributor Author

javer commented Sep 16, 2013

Yes, I am trying to find a solution which compatible with both PHP and HHVM.

@javer
Copy link
Contributor Author

javer commented Sep 16, 2013

Done.

@beberlei
Copy link
Member

Would there be a way to have a HvvmPdoConnection instead and changing just that one? This is annoying to burden all normal users with.

@javer
Copy link
Contributor Author

javer commented Sep 16, 2013

It is only implementation of declared interface, nothing more. As I wrote above, it is a bit strange that PHP allows

class PDOConnection extends PDO implements Connection

when methods declarations differ in PDO and Connection without explicit implementation of this methods. It is possible only due to weak checking of inheritance, so it can be treated as "hack" and can be broken in any new version of PHP.

HHVM does not have another PDO implementation, it is compatible with PHP PDO. So creating separated class PDOConnection only for HHVM will lead to a lot of changes in source code, because there are many classes which inherit PDOConnection and PDOStatement.

@lsmith77
Copy link
Member

unfortunately the creator of PDO thought it would be wise for PDO to not follow the standard PHP OO model. another solution could be to try and clean that up for PHP 5.6

@letharion
Copy link

With a quick test under HHVM this PR appears to work. Can't speak for normal php at this time, but I assume most others are able to comment on that, and that Travis reporting success also means that the tests run well with normal php.

+1 @javer :)

@JoelMarcey
Copy link

Any timeframe for when this pull request will be merged? cc: @guilhermeblanco

@guilhermeblanco
Copy link
Member

@JoelMarcey I'm getting close to look into pending HHVM support in a few days.
Today I'll probably make a round on Riak PECL extension and probably tomorrow I'll spin up HHVM 2.2.X and spend 2 days getting Doctrine to work there. It's a bit hard when you contribute to a thousand OSS. =P

@joshuataylor
Copy link

Sorry to pester you @guilhermeblanco , but did you ever take a look at this?

Really love doctrine, would love to get it to run under HHVM. :)

@stof
Copy link
Member

stof commented Nov 22, 2013

I think I know what the issue is on HHVM and it will impact all projects relying on the PDO methods to fulfill their interface applied on a child class: the HHVM definition for PDO uses scalar typehints for its methods (which is possible in HHVM), which means it has a different signature than the official PDO.

@letharion
Copy link

@stof I'm not sure what you base that on. Yes, HHVM allows use of scalar type hints, but I don't know how that's relevant to this issue.

Doctrine alters the signature of a function, as pointed out by @lsmith77 above. HHVM is strict about this, and refuses to guess which signature is correct, whereas Zend allows multiple signatures, and probably uses some heuristic to determine which one to use.

@JoelMarcey
Copy link

Hi all,

What can we do to get this pull request accepted? I would love to have our HHVM framework test script not to have to rely on a fork to have doctrine2 to test correctly on HHVM. I want to be able to git clone from doctrine itself.

@Ocramius
Copy link
Member

I'm actually 👍 to this - at least for us, the suite seems to pass all tests.

@javer can you complete coverage?

coverage

@JoelMarcey
Copy link

cc: @ptarjan

@beberlei
Copy link
Member

@JoelMarcey I really don't like that it makes the code so ugly. Is there no way to provide two implementations of these classes and have a working one being picked up by HHVM?

@JoelMarcey
Copy link

@beberlei Assuming you are talking about 7aa02d0

While I am not quite sure what you mean by "ugly" --- all this code is doing is explicitly implementing the functions of the interface that the class is declared to implement ---- an option I guess is to have two classes, one of which is named, let's say:

class PDOConnection_HHVM extends PDO implements Connection

and a "require" statement based on an "if this is HHVM".

Not sure if that is any prettier or not. Beauty is in the eye of the beholder, I suppose.

To be honest, I don't care if we have to do that workaround for now, as long as we can reference the doctrine2 github repository "master" branch directly in our testing without a bunch of forks and pull requests.

@beberlei
Copy link
Member

@JoelMarcey Would that work not to instantiate this classes, if we are on HHVM and it wouldnt complain about them not being compatible? Rephrased, does HHVM care about non compatible code, when its never require'ed?

@beberlei
Copy link
Member

@JoelMarcey if yes, how do i check for "if this is HHVM".

@beberlei
Copy link
Member

@JoelMarcey just realized we keep extending from it, so we have to use this approach.

beberlei added a commit that referenced this pull request Dec 13, 2013
HHVM compatibility: implement declared interfaces
@beberlei beberlei merged commit 4d23c7b into doctrine:master Dec 13, 2013
@beberlei
Copy link
Member

@JoelMarcey We are seeing failures with the default DateTime zone on the travis hhvm builds: https://travis-ci.org/doctrine/dbal

@JoelMarcey
Copy link

@beberlei Awesome! Thanks for the merge! :)

Let me see about the DateTimeZone issues you are having.

@JoelMarcey
Copy link

@beberlei Are you still seeing failures on travis? Maybe I am missing them...

@Ocramius
Copy link
Member

@ptarjan
Copy link

ptarjan commented Dec 13, 2013

Travis needs to set a default datetime. You can try hacking around it @JoelMarcey by making a /etc/hhvm/php.ini with

date.timezone=UTC

in it

@stof
Copy link
Member

stof commented Dec 14, 2013

@beberlei already reported: travis-ci/travis-cookbooks#248

@chregu
Copy link

chregu commented Dec 17, 2013

Thanks and very cool. Seems to work in our project now

You may add a comment or addition here:

https://github.com/facebook/hhvm/wiki/OSS-PHP-Frameworks-Unit-Testing:-Doctrine

@micaelmalta
Copy link

@beberlei is this better ? 31bf86d

@Ocramius
Copy link
Member

Ocramius commented Mar 4, 2014

@mmicael1 that code was in place because of performance optimizations... I don't mind to see it go, but we should first verify how much is being eaten up.

@stof
Copy link
Member

stof commented Mar 4, 2014

@mmicael1 IIRC, func_get_args() has to be in the first line of the method for HHVM because of the optimization they perform in repo authoritative mode.

@micaelmalta
Copy link

@stof I found the thread they talk about: facebook/hhvm#1027

Commit updated af9fbe1

@hardchor
Copy link

hardchor commented Apr 4, 2014

Could that get merged into the 2.3 branch?

@Ocramius
Copy link
Member

Ocramius commented Apr 4, 2014

@hardchor 2.3 won't get any new features merged in.

unknownnf added a commit to unknownnf/dbal that referenced this pull request May 12, 2014
@dominikzogg
Copy link

@Ocramius do you have an idea, why i still get this error? https://travis-ci.org/saxulum/saxulum-doctrine-orm-manager-registry-provider/jobs/37031287

@deeky666
Copy link
Member

deeky666 commented Oct 4, 2014

@dominikzogg do you actually use DBAL master branch? The patch is not available in version <2.5.

@dominikzogg
Copy link

@deeky666 oh, ok thx, i missunderstood it, meant its fixed in 2.4

stefanotorresi pushed a commit to stefanotorresi/thorr-oauth2-doctrine that referenced this pull request Nov 26, 2014
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 25, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.