ID:               28165
 Comment by:       hans at velum dot net
 Reported By:      daniel at rozsnyo dot com
 Status:           Suspended
 Bug Type:         Feature/Change Request
 Operating System: *
 PHP Version:      5.0.*
 New Comment:

Using '===' instead of '==' will work, but is semantically different,
right?

$a === $b : are object references the same? i.e. are $a and $b the same
instance.

$a == $b : do the contents match? i.e. do all the variables in object
$a have the same values as the vars in object $b.

If '==' is going to be changed to mean something else, then I think
PHP5 needs an __equals() method so that object contents comparison can
be accomplished.


Previous Comments:
------------------------------------------------------------------------

[2004-04-26 21:11:55] rozsnyo at kn dot vutbr dot cz

The notices are also generated on comparison operator (==)

This code:
<?php

  class A {
    public $p;
    function __construct($ip) { $this->p = $ip; }
  }

  $x = new A(1);
  $y = $z = new A(2);

  echo '$x,$y is ' , ( ($x ==  $y) ? 'equal'            : 'not
equal[right]'     ), '<br>';
  echo '$x,$y is ' , ( ($x === $y) ? 'identical'        : 'not
identical[right]' ), '<br>';
  echo '$z,$y is ' , ( ($z ==  $y) ? 'equal[right]'     : 'not equal'  
         ), '<br>';
  echo '$z,$y is ' , ( ($z === $y) ? 'identical[right]' : 'not
identical'        ), '<br>';

?>

Produces:

$x,$y is 
Notice: Object of class A could not be converted to integer in
C:\www\default\test\index.php on line 11

Notice: Object of class A could not be converted to integer in
C:\www\default\test\index.php on line 11
not equal[right]
$x,$y is not identical[right]
$z,$y is 
Notice: Object of class A could not be converted to integer in
C:\www\default\test\index.php on line 13

Notice: Object of class A could not be converted to integer in
C:\www\default\test\index.php on line 13
equal[right]
$z,$y is identical[right]


At least, please remove the notification and fix the in_array and also
the array_search function (seems that both share the same algorithm -
always two notices as two objects are compared) - the right solution
would be to use the === operator in these functions when the needle is
an object.

This bug is still about:

http://www.php.net/ChangeLog-5.php 
Changed array_search() to accept also objects as a needle. (Moriyoshi)

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

[2004-04-26 20:39:34] [EMAIL PROTECTED]

There are no plans for this. Maybe in PHP 6.

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

[2004-04-26 19:10:48] daniel at rozsnyo dot com

Description:
------------
While the docs says that i can use use objects as needle, i actually
can not - it might be missing some implicit conversion to integer from
objects.
(I use the published RC2 version (for win32), not the CVS version, the
RC2 option is not available in the listbox for posting a bug-report)

Another problem is the notice (in RC1 there was no notice, here is a
notice... so I am posting as bug... by the way, it would be nice to
have functions like __toInteger() [in_array], __toArray() [for] 
besides the known __toString [echo,print]

Daniel

Reproduce code:
---------------
<?php

  class A { }
  $a = Array( new A, new A, new A );
  echo $x = new A; // should be object # 4
  echo (in_array($x,$a)) ? 'There' : 'NOT there';

?>

Expected result:
----------------
I am expecting this result:
---
Object id #4
NOT there


Actual result:
--------------
Look to notices:
---
Object id #4
Notice: Object of class A could not be converted to integer in
C:\www\default\test\index.php on line 9

Notice: Object of class A could not be converted to integer in
C:\www\default\test\index.php on line 9
There


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


-- 
Edit this bug report at http://bugs.php.net/?id=28165&edit=1

Reply via email to