#29917 [Com]: isset() always return

2004-09-09 Thread fch at hexanet dot fr
 ID:   29917
 Comment by:   fch at hexanet dot fr
 Reported By:  dasch at ulmail dot net
 Status:   Wont fix
 Bug Type: Feature/Change Request
 Operating System: *
 PHP Version:  5.*
 Assigned To:  Andi
 New Comment:

The problem was not that __set() and __get() are slow.
The problem is that, if __get() and __set() are defined in an object,
PHP becomes unconsistent, that is to say that some functions like
isset() have not these usual behavior if __get() and __set() are
defined in an object.
And abstract properties is a very strange concept...
However, a __get() and __set() optimization is a good idea.

Fred.


Previous Comments:


[2004-09-03 20:30:43] [EMAIL PROTECTED]

We'd need to all __get() for every non existing property then which
would be worse than only a mahor slowdown.
Een a __exists() would'n help much because that, too. Would be very
slow. The only way out would be to declare abstract properties as
allowed by this patch:

http://marcus-boerger.de/php/ext/ze2/ze2-abstract-properties-20040803.diff.txt




[2004-09-03 13:48:23] fch at hexanet dot fr

?php

class foo implements arrayAccess
{
   private $array = array();

   function __construct() {}

   function __get($key)
   {
  return $this-offsetGet($key);
   }

   function __set($key, $value)
   {
  $this-offsetSet($key, $value);
   }

   function offsetExists($key)
   {
  return isset($this-array[$key]);
   }

   function offsetGet($key)
   {
  return $this-array[$key];
   }

   function offsetSet($key, $value)
   {
  $this-array[$key] = $value;
   }

   function offsetUnset($key)
   {
  unset($this-array[$key];
   }
}

$foo = new foo();

echo (isset($foo['bar']) == true ? 'set' : 'not set');
$foo['bar'] = 'bar';
echo (isset($foo['bar']) == true ? 'set' : 'not set');
echo $foo['bar'];

#Expected result :
# not set
# set
# bar
#Real result
# not set
# set
# bar
# !! GREAT !!

#Now, the same thing with __get() and __set()

unset($foo);
$foo = new foo();

echo (isset($foo-array) == true ? 'array is set' : 'array is not
set');
echo (isset($foo-bar) == true ? 'bar is set' : 'bar is not set');
$foo-bar = 'bar';
echo (isset($foo['bar']) == true ? 'bar is set' : 'bar is not set');
echo $foo-bar;

#Expected result :
# array is set
# bar is not set
# bar is set
# bar
#Real result
# array is set # Ok !
# bar is not set # Ok !
# bar is not set # PROBLEM PROBLEM
# bar
# !! NOT GREAT !!

?

It is abnormal !
isset() does not return the good value on property wich was set with
__set() it is return the good value on property wich was set in the
class,and isset() return the good value on value wich was set with
offsetSet() method !!
It is a paradox !

I think that isset MUST return the same value in all case.



[2004-09-01 13:51:05] dasch at ulmail dot net

If the isset() function aren't going to work with properties accessed
with a __get() call, then there should at least be a __isset() method
that allows for custom isset()-handling. eg:

?php

class Foo
{
private $bar = bar;

public function __isset ($prop)
{
if (isset($this-$prop)) {
return TRUE;
} else {
return FALSE;
}
}
}

$foo = new Foo();

echo isset($foo-bar) ? yes\n : no\n;

// Should be the same as

echo $foo-__isset('bar') ? yes\n : no\n;

?



[2004-09-01 10:24:01] fch at hexanet dot fr

Can you explain where are wrong ???

A call to __set() create a property in the object (see documentation).
Event if this property is not a real member property for PHP language
point of view, for the programers point of view, it is a property !

So, isset() MUST return true in my example.

What are difference between your example :

$o-a = 'bar';
echo isset($o-a) ? yes\n : no\n;

And my example :

$o-foo = 'bar';
echo (isset($o-foo) == true ? 'foo is set' : 'foo is not set');

There is no difference ! Except that my foo property was created with a
__set() call.



[2004-09-01 10:14:10] [EMAIL PROTECTED]

No, you're wrong. The behavior you see is the correct behavior.



The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at
http://bugs.php.net/29917

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


#29917 [Com]: isset() always return

2004-09-03 Thread fch at hexanet dot fr
 ID:   29917
 Comment by:   fch at hexanet dot fr
 Reported By:  dasch at ulmail dot net
 Status:   Bogus
 Bug Type: Class/Object related
 Operating System: Linux
 PHP Version:  5.0.1
 New Comment:

?php

class foo implements arrayAccess
{
   private $array = array();

   function __construct() {}

   function __get($key)
   {
  return $this-offsetGet($key);
   }

   function __set($key, $value)
   {
  $this-offsetSet($key, $value);
   }

   function offsetExists($key)
   {
  return isset($this-array[$key]);
   }

   function offsetGet($key)
   {
  return $this-array[$key];
   }

   function offsetSet($key, $value)
   {
  $this-array[$key] = $value;
   }

   function offsetUnset($key)
   {
  unset($this-array[$key];
   }
}

$foo = new foo();

echo (isset($foo['bar']) == true ? 'set' : 'not set');
$foo['bar'] = 'bar';
echo (isset($foo['bar']) == true ? 'set' : 'not set');
echo $foo['bar'];

#Expected result :
# not set
# set
# bar
#Real result
# not set
# set
# bar
# !! GREAT !!

#Now, the same thing with __get() and __set()

unset($foo);
$foo = new foo();

echo (isset($foo-array) == true ? 'array is set' : 'array is not
set');
echo (isset($foo-bar) == true ? 'bar is set' : 'bar is not set');
$foo-bar = 'bar';
echo (isset($foo['bar']) == true ? 'bar is set' : 'bar is not set');
echo $foo-bar;

#Expected result :
# array is set
# bar is not set
# bar is set
# bar
#Real result
# array is set # Ok !
# bar is not set # Ok !
# bar is not set # PROBLEM PROBLEM
# bar
# !! NOT GREAT !!

?

It is abnormal !
isset() does not return the good value on property wich was set with
__set() it is return the good value on property wich was set in the
class,and isset() return the good value on value wich was set with
offsetSet() method !!
It is a paradox !

I think that isset MUST return the same value in all case.


Previous Comments:


[2004-09-01 13:51:05] dasch at ulmail dot net

If the isset() function aren't going to work with properties accessed
with a __get() call, then there should at least be a __isset() method
that allows for custom isset()-handling. eg:

?php

class Foo
{
private $bar = bar;

public function __isset ($prop)
{
if (isset($this-$prop)) {
return TRUE;
} else {
return FALSE;
}
}
}

$foo = new Foo();

echo isset($foo-bar) ? yes\n : no\n;

// Should be the same as

echo $foo-__isset('bar') ? yes\n : no\n;

?



[2004-09-01 10:24:01] fch at hexanet dot fr

Can you explain where are wrong ???

A call to __set() create a property in the object (see documentation).
Event if this property is not a real member property for PHP language
point of view, for the programers point of view, it is a property !

So, isset() MUST return true in my example.

What are difference between your example :

$o-a = 'bar';
echo isset($o-a) ? yes\n : no\n;

And my example :

$o-foo = 'bar';
echo (isset($o-foo) == true ? 'foo is set' : 'foo is not set');

There is no difference ! Except that my foo property was created with a
__set() call.



[2004-09-01 10:14:10] [EMAIL PROTECTED]

No, you're wrong. The behavior you see is the correct behavior.



[2004-09-01 09:59:01] fch at hexanet dot fr

?php

class OO
{
private $array = array();

function __construct() {}

function __set($name, $value)
{
$this-array[$name] = $value;
}

function __get($name)
{
if (isset($this-array[$name]) == true)
return null;
else
return $this-array[$name];
}
}

$o = new oo();
$o-foo = 'bar';
echo (isset($o-foo) == true ? 'foo is set' : 'foo is not set');

#Expecting result
# = foo is set
#Real result
# = foo is not set

?

If PHP provide __set() and __get() function in order to create property
dynamicaly, PHP function like isset() MUST BE USED with these dynamic
properties as usual.
So, in my example, isset() MUST return TRUE !! and not FALSE !!



[2004-09-01 08:41:52] [EMAIL PROTECTED]

This works fine for me:

[EMAIL PROTECTED]:~$ cat bug29917.php
?php
class oo {
var $a;
}

$o = new oo;
echo isset($o-a) ? yes\n : no\n;
$o-a = 'bar';
echo isset($o-a) ? yes\n : no\n;
?
[EMAIL PROTECTED]:~$ php bug29917.php
no
yes


Come up with a short example like mine that shows that it doesn't work.
Just saying $o-a won't work doesn't help.


#29917 [Com]: isset() always return

2004-09-01 Thread fch at hexanet dot fr
 ID:   29917
 Comment by:   fch at hexanet dot fr
 Reported By:  dasch at ulmail dot net
 Status:   Bogus
 Bug Type: Class/Object related
 Operating System: Linux
 PHP Version:  5.0.1
 New Comment:

?php

class OO
{
private $array = array();

function __construct() {}

function __set($name, $value)
{
$this-array[$name] = $value;
}

function __get($name)
{
if (isset($this-array[$name]) == true)
return null;
else
return $this-array[$name];
}
}

$o = new oo();
$o-foo = 'bar';
echo (isset($o-foo) == true ? 'foo is set' : 'foo is not set');

#Expecting result
# = foo is set
#Real result
# = foo is not set

?

If PHP provide __set() and __get() function in order to create property
dynamicaly, PHP function like isset() MUST BE USED with these dynamic
properties as usual.
So, in my example, isset() MUST return TRUE !! and not FALSE !!


Previous Comments:


[2004-09-01 08:41:52] [EMAIL PROTECTED]

This works fine for me:

[EMAIL PROTECTED]:~$ cat bug29917.php
?php
class oo {
var $a;
}

$o = new oo;
echo isset($o-a) ? yes\n : no\n;
$o-a = 'bar';
echo isset($o-a) ? yes\n : no\n;
?
[EMAIL PROTECTED]:~$ php bug29917.php
no
yes


Come up with a short example like mine that shows that it doesn't work.
Just saying $o-a won't work doesn't help.



[2004-08-31 19:35:52] dasch at ulmail dot net

Still not resolved, you still have to use the following code to access
the properties:

$a = $o-a;
echo isset($a) ? yes\n : no\n;

Another guy thought that it would be neat if there was a __isset magic
method.



[2004-08-31 16:27:11] fch at hexanet dot fr

Sorry, but if you do that :
$o-a = 'foo';
echo isset($o-a) ? yes\n : no\n;
Expected result was true, but actual result is false !
And $o-a is set !



[2004-08-31 16:20:45] [EMAIL PROTECTED]

Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

This is correct, the isset() checks if a variable is set or not. In
your case it\'s simply not set (it will be set after __get() is
executed on it once).



[2004-08-31 16:00:43] dasch at ulmail dot net

Description:

When trying to determine whether or not a property in an overloaded
object is set, isset() always returns FALSE. This is not the case with
objects that isn't overloaded (doesn't have a __get() method defined).

Reproduce code:
---
?php

class OO
{
private $elem = array(a = 1);

public function __get ($prop)
{
if (isset($this-elem[$prop])) {
return $this-elem[$prop];
} else {
return NULL;
}
}

public function __set ($prop, $val)
{
$this-elem[$prop] = $val;
}
}

$o = new OO();

echo isset($o-a) ? yes\n : no\n;
echo isset($o-b) ? yes\n : no\n;

echo is_null($o-a) ? yes\n : no\n;
echo is_null($o-b) ? yes\n : no\n;

?

Expected result:

yes
no
no
yes

Actual result:
--
no
no
no
yes





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


#29917 [Com]: isset() always return

2004-09-01 Thread fch at hexanet dot fr
 ID:   29917
 Comment by:   fch at hexanet dot fr
 Reported By:  dasch at ulmail dot net
 Status:   Bogus
 Bug Type: Class/Object related
 Operating System: Linux
 PHP Version:  5.0.1
 New Comment:

Can you explain where are wrong ???

A call to __set() create a property in the object (see documentation).
Event if this property is not a real member property for PHP language
point of view, for the programers point of view, it is a property !

So, isset() MUST return true in my example.

What are difference between your example :

$o-a = 'bar';
echo isset($o-a) ? yes\n : no\n;

And my example :

$o-foo = 'bar';
echo (isset($o-foo) == true ? 'foo is set' : 'foo is not set');

There is no difference ! Except that my foo property was created with a
__set() call.


Previous Comments:


[2004-09-01 10:14:10] [EMAIL PROTECTED]

No, you're wrong. The behavior you see is the correct behavior.



[2004-09-01 09:59:01] fch at hexanet dot fr

?php

class OO
{
private $array = array();

function __construct() {}

function __set($name, $value)
{
$this-array[$name] = $value;
}

function __get($name)
{
if (isset($this-array[$name]) == true)
return null;
else
return $this-array[$name];
}
}

$o = new oo();
$o-foo = 'bar';
echo (isset($o-foo) == true ? 'foo is set' : 'foo is not set');

#Expecting result
# = foo is set
#Real result
# = foo is not set

?

If PHP provide __set() and __get() function in order to create property
dynamicaly, PHP function like isset() MUST BE USED with these dynamic
properties as usual.
So, in my example, isset() MUST return TRUE !! and not FALSE !!



[2004-09-01 08:41:52] [EMAIL PROTECTED]

This works fine for me:

[EMAIL PROTECTED]:~$ cat bug29917.php
?php
class oo {
var $a;
}

$o = new oo;
echo isset($o-a) ? yes\n : no\n;
$o-a = 'bar';
echo isset($o-a) ? yes\n : no\n;
?
[EMAIL PROTECTED]:~$ php bug29917.php
no
yes


Come up with a short example like mine that shows that it doesn't work.
Just saying $o-a won't work doesn't help.



[2004-08-31 19:35:52] dasch at ulmail dot net

Still not resolved, you still have to use the following code to access
the properties:

$a = $o-a;
echo isset($a) ? yes\n : no\n;

Another guy thought that it would be neat if there was a __isset magic
method.



[2004-08-31 16:27:11] fch at hexanet dot fr

Sorry, but if you do that :
$o-a = 'foo';
echo isset($o-a) ? yes\n : no\n;
Expected result was true, but actual result is false !
And $o-a is set !



The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at
http://bugs.php.net/29917

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


#29917 [Com]: isset() always return

2004-08-31 Thread fch at hexanet dot fr
 ID:   29917
 Comment by:   fch at hexanet dot fr
 Reported By:  dasch at ulmail dot net
 Status:   Bogus
 Bug Type: Class/Object related
 Operating System: Linux
 PHP Version:  5.0.1
 New Comment:

Sorry, but if you do that :
$o-a = 'foo';
echo isset($o-a) ? yes\n : no\n;
Expected result was true, but actual result is false !
And $o-a is set !


Previous Comments:


[2004-08-31 16:20:45] [EMAIL PROTECTED]

Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

This is correct, the isset() checks if a variable is set or not. In
your case it\'s simply not set (it will be set after __get() is
executed on it once).



[2004-08-31 16:00:43] dasch at ulmail dot net

Description:

When trying to determine whether or not a property in an overloaded
object is set, isset() always returns FALSE. This is not the case with
objects that isn't overloaded (doesn't have a __get() method defined).

Reproduce code:
---
?php

class OO
{
private $elem = array(a = 1);

public function __get ($prop)
{
if (isset($this-elem[$prop])) {
return $this-elem[$prop];
} else {
return NULL;
}
}

public function __set ($prop, $val)
{
$this-elem[$prop] = $val;
}
}

$o = new OO();

echo isset($o-a) ? yes\n : no\n;
echo isset($o-b) ? yes\n : no\n;

echo is_null($o-a) ? yes\n : no\n;
echo is_null($o-b) ? yes\n : no\n;

?

Expected result:

yes
no
no
yes

Actual result:
--
no
no
no
yes





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