Re: [PHP-DEV] is_callable & Bug 20216

2002-11-18 Thread Andrei Zmievski
On Mon, 18 Nov 2002, Leon Atkinson wrote:
> Hmm...OK.  Yes, that does make is_callable return false.  Can you explain
> the logic behind this?  I tried lots of other values and got TRUE.  For
> example:
> 
> var_dump(is_callable(array('$$$','%^&'), true));
> var_dump(is_callable('%^&', true));
> 
> These aren't valid identifiers, but the function is (apparently) reporting
> that syntax is OK.

The syntax check is only intended to reject arrays that don't have a
valid structure to be used as callbacks. The valid ones are supposed to
have only 2 entries, the first of which is an object or a string, and
the second one is a string. The function doesn't do any checking of the
contents of the array.

> Ah, yeah, I guess there isn't a way to tell if a method is callable
> statically or not unless you check that it contains no references to
> instance properties.
> 
> So, would it be fair to say this function is intended for debugging the
> core?  And, if you have the time, could you describe the situation where
> this function is useful?

It is useful when you have a function that takes a callback as a
parameter and it needs to check whether that callback is, in fact,
callable.

-Andrei   http://www.gravitonic.com/
* We are not a clone. *

-- 
PHP Development Mailing List 
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP-DEV] is_callable & Bug 20216

2002-11-18 Thread Leon Atkinson
> > The second argument seems to be for checking syntax only, but I can't
> > figure out how to make is_callable return FALSE when the second
> > argument is TRUE.
>
> Try this:
>
> var_dump(is_callable(array(1,2), true));

Hmm...OK.  Yes, that does make is_callable return false.  Can you explain
the logic behind this?  I tried lots of other values and got TRUE.  For
example:

var_dump(is_callable(array('$$$','%^&'), true));
var_dump(is_callable('%^&', true));

These aren't valid identifiers, but the function is (apparently) reporting
that syntax is OK.


> Well, $name is just supposed to indicate which class/method you were
> checking. It doesn't tell you whether the method is static or not,
> because in PHP 4 it doesn't make sense.

Ah, yeah, I guess there isn't a way to tell if a method is callable
statically or not unless you check that it contains no references to
instance properties.

So, would it be fair to say this function is intended for debugging the
core?  And, if you have the time, could you describe the situation where
this function is useful?

Thanks Much!

Leon



-- 
PHP Development Mailing List 
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP-DEV] is_callable & Bug 20216

2002-11-18 Thread Andrei Zmievski
Since I wrote the function, I can provide some insight.

On Mon, 18 Nov 2002, Leon Atkinson wrote:
> This function wraps zend_is_callable.  The first argument is the name
> of a function or method.  Class and object methods are specified by
> passing an array with two elements: class or object and method name.

Right.

> The second argument seems to be for checking syntax only, but I can't
> figure out how to make is_callable return FALSE when the second
> argument is TRUE.

Try this:

var_dump(is_callable(array(1,2), true));

> The third argument receives the "callable name".  In the example below
> it's "a::b".  Note, however, that despite the implication that a::b()
> is a callable static method, this is not the case.
> 
>class a
>   {
> var $c;
> 
> function b()
>{
>  return($this->c);
> }
>   }
> 
>   $d = new a;
> 
>   if(is_callable(array($d, 'b'), FALSE, $name))
>   {
> print($name);
>   }
> ?>

Well, $name is just supposed to indicate which class/method you were
checking. It doesn't tell you whether the method is static or not,
because in PHP 4 it doesn't make sense.

-Andrei   http://www.gravitonic.com/

Politics is for the moment, an equation is for eternity.
   
   -- Albert Einstein

-- 
PHP Development Mailing List 
To unsubscribe, visit: http://www.php.net/unsub.php




[PHP-DEV] is_callable & Bug 20216

2002-11-18 Thread Leon Atkinson
Can someone shed some light on is_callable?  I think I understand it's meant
for testing whether a function or method is callable, but it would be nice
to get some confirmation from someone who knows for sure.  Philip and I are
trying to add this function to the manual.

Here are some rough notes I have on my understanding of the function (from
http://bugs.php.net/bug.php?id=20216):

This function wraps zend_is_callable.  The first argument is the name
of a function or method.  Class and object methods are specified by
passing an array with two elements: class or object and method name.

The second argument seems to be for checking syntax only, but I can't
figure out how to make is_callable return FALSE when the second
argument is TRUE.

The third argument receives the "callable name".  In the example below
it's "a::b".  Note, however, that despite the implication that a::b()
is a callable static method, this is not the case.

c);
}
  }

  $d = new a;

  if(is_callable(array($d, 'b'), FALSE, $name))
  {
print($name);
  }
?>

Thanks!

---
Leon Atkinson 


-- 
PHP Development Mailing List 
To unsubscribe, visit: http://www.php.net/unsub.php