Edit report at https://bugs.php.net/bug.php?id=62519&edit=1

 ID:                 62519
 Comment by:         ni...@php.net
 Reported by:        awilliams at linkme dot com dot au
 Summary:            Find out about a function's call context
 Status:             Open
 Type:               Feature/Change Request
 Package:            Unknown/Other Function
 Operating System:   any
 PHP Version:        Irrelevant
 Block user comment: N
 Private report:     N

 New Comment:

PHP is a dynamically typed language. It can't in the general case know what 
type is expected. Simple example if f1() + f2(). Here int, float and array 
would be viable return types.

Whether the return value is used or not is known to the engine and also exposed 
to internal functions.

But I don't think that it makes sense to expose it to userland functions. 
Functions shouldn't behave different based on whether the return value is used 
or not.


Previous Comments:
------------------------------------------------------------------------
[2012-07-10 04:10:55] awilliams at linkme dot com dot au

Description:
------------
I would like to be able to tell if a function was called from a context that is 
expecting a return value or not.  Additionally what type is expected.
 
 eg('hello');                // called not expecting a return value
 echo eg('hello').' world';  // called expecting a string


function eg($s)
{
  if(return){  // suggested overloading of the return keyword to report the 
function context.
    return ($s);
  }
  else{
    echo $s;
  }
}

Additionally 
 gettype(return);
 and
 is_string(return);
 is_array(return); 
etc



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



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

Reply via email to