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

6.x compatible with php8.0 #1977

Closed

Conversation

AskaoAhmedSaad
Copy link

make version 6.x compatible with php8.0

@AskaoAhmedSaad AskaoAhmedSaad changed the base branch from master to 6.x September 10, 2021 10:12
Copy link
Owner

@ruflin ruflin left a comment

Choose a reason for hiding this comment

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

@AskaoAhmedSaad It would be nice if we could make 6.x compatible with PHP 8.0 but we should not make it a breaking change for existing users. Any ideas on how we can make it non breaking? I remember we had similar challenges with other PHP versions and reserved terms. Can you check it how we have solved it in other places / PR?

@@ -1,216 +0,0 @@
<?php
Copy link
Owner

Choose a reason for hiding this comment

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

This looks like a breaking change?

Copy link
Contributor

Choose a reason for hiding this comment

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

It definitely is :)

@reedy
Copy link
Contributor

reedy commented Sep 22, 2021

I was going to try and make a similar patch...

Don't remove the Match class; if it exists and isn't executed (thanks to the magic that is the autoloader; unless new Match or similar exists, it will be ignored), it won't be a problem for PHP 8.0.

Swap Match and MatchQuery around (so the Match alias extends MatchQuery instead of the other way around), and then update documentation.

If people are still using Match as the canonical in their own code, they'll need to update that to work on PHP 8.0 anyway, so that's not a problem. Anyone still using Match and not needing to support PHP 8.0 doesn't need to make any changes.

@@ -12,7 +12,7 @@
}
],
"require": {
"php": "^7.0",
"php": "^7.0 | ^8.0",
Copy link
Contributor

Choose a reason for hiding this comment

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

* @deprecated since version 6.1.2, use the MatchQuery class instead.
* @see https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-match-query.html
*/
class Match extends AbstractQuery
Copy link
Contributor

Choose a reason for hiding this comment

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

This should become class Match extends MatchQuery and otherwise be empty of content

Copy link
Contributor

Choose a reason for hiding this comment

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

Keeping the comments above too, of course.

@@ -3,7 +3,7 @@
namespace Elastica\Query;

/**
* Match none query. Returns no results.
* MatchQuery none query. Returns no results.
Copy link
Contributor

Choose a reason for hiding this comment

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

@@ -3,7 +3,7 @@
namespace Elastica\Query;

/**
* Match all query. Returns all results.
* MatchQuery all query. Returns all results.
Copy link
Contributor

Choose a reason for hiding this comment

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

This shouldn't be replaced.

@@ -3,7 +3,7 @@
namespace Elastica\Query;

/**
* Match Phrase query.
* MatchQuery Phrase query.
Copy link
Contributor

Choose a reason for hiding this comment

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

This shouldn't be replaced.

@@ -94,7 +94,7 @@ public function setOperator($operator = self::OPERATOR_OR)
}

/**
* Set field minimum should match for Match Query.
* Set field minimum should match for MatchQuery Query.
Copy link
Contributor

Choose a reason for hiding this comment

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

This shouldn't be replaced.

@@ -106,7 +106,7 @@ public function setMinimumShouldMatch($minimumShouldMatch)
}

/**
* Set zero terms query for Match Query.
* Set zero terms query for MatchQuery Query.
Copy link
Contributor

Choose a reason for hiding this comment

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

This shouldn't be replaced.

@@ -120,7 +120,7 @@ public function setZeroTermsQuery($zeroTermQuery = self::ZERO_TERM_NONE)
}

/**
* Set cutoff frequency for Match Query.
* Set cutoff frequency for MatchQuery Query.
Copy link
Contributor

Choose a reason for hiding this comment

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

This shouldn't be replaced.

@@ -26,7 +26,7 @@ public function testPercolateQueryOnNewDocument()
$doc = new Document(2, ['message' => 'A new bonsai tree in the office']);
$this->documentType->addDocument($queryDoc);
$this->index->refresh();
//Match a document to the registered percolator queries:
//MatchQuery a document to the registered percolator queries:
Copy link
Contributor

Choose a reason for hiding this comment

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

This shouldn't be replaced.

@@ -40,7 +40,7 @@ public function testPercolateQueryOnNewDocument()
$this->index->refresh();
$resultSet = $this->index->search($percolateQuery);

//Match a document to the registered percolator queries:
//MatchQuery a document to the registered percolator queries:
Copy link
Contributor

Choose a reason for hiding this comment

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

This shouldn't be replaced.

@reedy
Copy link
Contributor

reedy commented Sep 22, 2021

Looks like this has just been done as a literal find and replace. Only really the code uses of the Match query needed updating. Replacing most (all?) of the Match comments with MatchQuery make no sense and don't align with what's on master.

And reverting them makes the diff smaller for people to review.

@AskaoAhmedSaad
Copy link
Author

@reedy @ruflin having a class with the name "Match" gives a parser error at PHP 8 environment, do you have a suggestion to overcome this and at the same time not to break the other PHP versions ?

I think maybe we can have a special version name with removing Match class totally and replace it with MatchQuery

@reedy
Copy link
Contributor

reedy commented Sep 22, 2021

@reedy @ruflin having a class with the name "Match" gives a parser error at PHP 8 environment, do you have a suggestion to overcome this and at the same time not to break the other PHP versions ?

I think maybe we can have a special version name with removing Match class totally and replace it with MatchQuery

It should only error if you execute the file using it (or lint it etc)... What are you doing to cause/see that error?

@reedy
Copy link
Contributor

reedy commented Sep 23, 2021

I re-made your commit without the comment changes in https://github.com/reedy/Elastica/tree/6xphp8

composer.json:

{
	"require": {
		"ruflin/elastica": "dev-6xphp8 as 6.2"
	},
	"repositories": [
		{
			"type": "git",
			"url": "https://github.com/reedy/elastica.git"
		}
	]
}

Test PHP script:

<?php

require __DIR__ . '/vendor/autoload.php';

use Elastica\Query\MatchQuery;

$mq = new MatchQuery();
echo "Done\n";

Run it

reedy@MacBook-Pro elasticatest % php --version    
PHP 8.0.10 (cli) (built: Aug 26 2021 15:36:17) ( NTS )
Copyright (c) The PHP Group
Zend Engine v4.0.10, Copyright (c) Zend Technologies
    with Zend OPcache v8.0.10, Copyright (c), by Zend Technologies
reedy@MacBook-Pro elasticatest % php test.php 
Done

@reedy
Copy link
Contributor

reedy commented Sep 23, 2021

CI seems fine with the Match class existing too...

I've got #1981 to the point where I think I'm just fiddling with fixing up some minor test breakages (function calls that need updating)

@ruflin
Copy link
Owner

ruflin commented Sep 23, 2021

As #1981 goes more into the direction we want to go I'm going to close this PR for now. @AskaoAhmedSaad Thanks for kicking this off and I would appreciate if you could chime in on #1981 In case we change direction, we can still reopen this one.

@ruflin ruflin closed this Sep 23, 2021
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

Successfully merging this pull request may close these issues.

3 participants