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

 ID:          51280
 Comment by:  olamedia at gmail dot com
 Reported by: olamedia at gmail dot com
 Summary:     Calculate expression before using it as argument
 Status:      Bogus
 Type:        Feature/Change Request
 Package:     *General Issues
 PHP Version: 5.3.2

 New Comment:

well, summarizing, I think that



1. any expression MUST be evaluated before it can be used (as parameter
of 

function or anything).



2. it's buggy that __set() is not working in this special case.


Previous Comments:
------------------------------------------------------------------------
[2010-03-22 10:30:32] olamedia at gmail dot com

Precalculation can be useful for ORM, for example, giving ability to use
this 

construction:

$users->where($group->id = 2)



Also, this can be used for named parameters emulation:

class parameter{

  var $name;

  var $value;

  function __construct($name, $value){

    $this->name = $name;

    $this->value = $value;

  }

}

class parameters{

  var $data = array();

  function __set($name, $value){

    $this->data[$name] = new parameter($name, $value);

  }

  function __get($name){

    return $this->data[$name];

  }

}

function a(){

  var_dump(func_get_args());

}

$arg = new parameters();

a($arg->id = 3, $arg->x = 'some', $arg->y = 5);

------------------------------------------------------------------------
[2010-03-22 10:18:40] johan...@php.net

The order of the evaluation of function parameters is "undefined". (It
actually changed with 5.2 or so due to performance reasons)

------------------------------------------------------------------------
[2010-03-22 09:51:47] olamedia at gmail dot com

Sorry, my bad. This was an incomplete example. In first message there
was a good 

example, when $a->x is an object, and in both cases: a($a->x) and
a($a->x = 3) - I 

'm expecting object $a->x instead of assigned value because of __set()
function, 

which converts value to an object.

------------------------------------------------------------------------
[2010-03-22 09:43:51] olamedia at gmail dot com

> the value of "$a = 3" is 3



Here I'm talking about function arguments, not a simple assignments.



function b($a){

  // here expected resulting object $a, not just int(3)

  var_dump($a);

}

class a{}

$a = new a();

b($a->x = 3); // outputs int(3)

$a->x = 3

b($a); // outputs object(a)#2 (1) { ["x"]=> int(3) }

------------------------------------------------------------------------
[2010-03-21 21:07:08] hholz...@php.net

Expected behavior, see:



http://php.net/manual/en/language.operators.assignment.php



  [...]

  The value of an assignment expression is the value assigned. 

  That is, the value of "$a = 3" is 3.  

  [...]

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


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/bug.php?id=51280


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

Reply via email to