1
lolhangman
problem with criteria and unset
  • 2009/9/3 8:56

  • lolhangman

  • Just popping in

  • Posts: 2

  • Since: 2009/9/3 8


hello everybody,
I have a problem using criteria and unset function.
Issue is : whane I use cirteria in a function a a parameter and I use unset on that criteria in this function, when I exit function this criteria is empty.

first I call the function with my criteria

$eta_handler->getObjectWithJoin($criteria);

then I use unset in that function

function getObjectWithJoin( $criteria ){

.....

if (!empty($criteria->criteriaElements))
{
.....
foreach ($criteria->criteriaElements as $indice=>$criteriaElement)
{
...
unset($criteria->criteriaElements[$indice-$indice_eval]);
...
}

...

}

}


than I call my function a second time with my criteria
$eta_handler->getObjectWithJoin($criteria);

But this time criteriaElements is empty


I tried with a copy ($criteria2 = criteria) for the second call but I had same result.


Does anybody could explain me what happens or has an idea to have my criteria not empty i nthe second call of my function ?

thanks for that.

2
ghia
Re: problem with criteria and unset
  • 2009/9/3 9:53

  • ghia

  • Community Support Member

  • Posts: 4953

  • Since: 2008/7/3 1


Why do you do the unset, if you don't want it to be cleared?
Can you tell us, what is the purpose of your handler. It seems to gather information from two tables and in some repetive manner?
See also this.

3
trabis
Re: problem with criteria and unset
  • 2009/9/3 11:59

  • trabis

  • Core Developer

  • Posts: 2269

  • Since: 2006/9/1 1


You could use
function getObjectWithJoin($criteria){
   static 
$criteria2;
   
//handle $criteria and $criteria2
   //...
   //$criteria2 = result of handling
   //return $criteria2 or do whatever you need with it
}

or
function getObjectWithJoin(&$criteria){//pass criteria by reference

4
lolhangman
Re: problem with criteria and unset
  • 2009/9/3 12:54

  • lolhangman

  • Just popping in

  • Posts: 2

  • Since: 2009/9/3 8


hey, thank you for your but this wasn't the problem.
In fact I've found the answer :
instead of doing a copy like this :
$citeria2 = $criteria
I use the clone() function like this:
$criteria2 = clone($criteria)

but I still don't know why $criteria used in my fonction is not a copy of $criteria but is a reference...

Login

Who's Online

375 user(s) are online (292 user(s) are browsing Support Forums)


Members: 0


Guests: 375


more...

Donat-O-Meter

Stats
Goal: $100.00
Due Date: Nov 30
Gross Amount: $0.00
Net Balance: $0.00
Left to go: $100.00
Make donations with PayPal!

Latest GitHub Commits