Bug #74297 [Opn]: Simple comparison fails

[email protected] ("arjen at parse dot nl")
Newsgroups php.bugs
Message-ID <[email protected]>
Edit report at https://bugs.php.net/bug.php?id=74297&edit=1

 ID:                 74297
 User updated by:    arjen at parse dot nl
 Reported by:        arjen at parse dot nl
 Summary:            Simple comparison fails
 Status:             Open
 Type:               Bug
 Package:            opcache
 Operating System:   Linux
 PHP Version:        7.1.3
 Block user comment: N
 Private report:     N

 New Comment:

Test script sometimes does not fail on first run, so please try a few times..


Previous Comments:
------------------------------------------------------------------------
[2017-03-23 11:01:35] arjen at parse dot nl

Description:
------------
php-memcached 3.0.3
libmemcached 1.0.18
memcached 1.4.32
php 7.1.3

Both memcached and opcache needs to be loaded. opcache.enable_cli is not needed.

php -n -dextension=memcached.so -dzend_extension=opcache.so script.php


If the value ('test') set in memcached is changed, the script no longer fails.


($e == $a) === false, while ($a == $e) === true...

Test script:
---------------
<?php

class r
{
	public $d = ['test' => 'x'];

	public function m()
	{
		return [] + $this->d;
	}
}

(function()
{
	$m = new memcached;
	$m->addServer('127.0.0.1', 11211);
	$m->set('Something', 'test');

	$e = ['test' => 'x'];
	$a = (new r)->m();

	if (0 == ($e <=> $a))
		return 'success';

	var_dump([$e, $a]);
	var_dump([serialize($e), serialize($a)]);
	var_dump([
		'e === a' => $e === $a,
		'e == a' => $e == $a,
		'e <=> a' => $e <=> $a,
		'a <=> e' => $a <=> $e,
		'a === e' => $a === $e,
		'a == e' => $a == $e]
	);

	var_dump(debug_zval_dump($e), debug_zval_dump($a));

	die('this should not happen');
})();


Expected result:
----------------
success

Actual result:
--------------
array(2) {
  [0]=>
  array(1) {
    ["test"]=>
    string(1) "x"
  }
  [1]=>
  array(1) {
    ["test"]=>
    string(1) "x"
  }
}
array(2) {
  [0]=>
  string(25) "a:1:{s:4:"test";s:1:"x";}"
  [1]=>
  string(25) "a:1:{s:4:"test";s:1:"x";}"
}
array(6) {
  ["e === a"]=>
  bool(true)
  ["e == a"]=>
  bool(false)
  ["e <=> a"]=>
  int(1)
  ["a <=> e"]=>
  int(0)
  ["a === e"]=>
  bool(true)
  ["a == e"]=>
  bool(true)
}
array(1) refcount(1){
  ["test"]=>
  string(1) "x" refcount(1)
}
array(1) refcount(2){
  ["test"]=>
  string(1) "x" refcount(1)
}



------------------------------------------------------------------------



--
Edit this bug report at https://bugs.php.net/bug.php?id=74297&edit=1
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.