strange property of callback functions

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
tores
Forum Contributor
Posts: 120
Joined: Fri Jun 18, 2004 3:04 am

strange property of callback functions

Post by tores »

Hi

Have this strange fault. Here is the code:

Code: Select all

<?php
  function dependencies($aid, $sid){
    require_once('components/com_ordre/funksjoner.php');

    for($i = 0, $max = count($sid); $i < $max; $i++){

      /* Finner hvilke aktiviteter hver sveiseaktivitet er avhengig av  */
      $this->sekvens = $sid[$i]{1};
      echo "Before:".$this->sekvens."<br>";
      $filtered = array_filter($aid, array("parser", "callback"));

      /* Legger inn avhengigheter for aktuell sveiseaktivitet */
      foreach($filtered as $verdi){
	db('INSERT INTO #__poly_dependson( `actID1` , `actID2` ) '
	   . ' SELECT s.actID, t.actID FROM #__poly_orderactivities = s, #__poly_orderactivities = t'
	   . ' WHERE ( ( s.drumID = '''.$sid[$i].''' AND s.articleID = '''.$this->ID.''' )'
	   . ' AND ( t.drumID = '''.$verdi.''' AND t.articleID = '''.$this->ID.''' ) )'); 
      }
    }
  }
  
  function callback($id){
    echo "Inside:".$this->sekvens."<br>";
    return ($id{1} == $this->sekvens);
  }

?>
The variable "sekvens" is a global variable in the class "parser". I set it in the function dependencies but when i access it in the callback-function it's unset. With other words "Before:" prints but "Inside:" doesn't. I can't seem to get around this problem. Anyone know how this can be solved?
contact_bogomil
Forum Newbie
Posts: 22
Joined: Mon May 27, 2002 8:13 am
Location: Sofia, Bulgaria
Contact:

re

Post by contact_bogomil »

what is your PHP version. Let this var become a global one.
tores
Forum Contributor
Posts: 120
Joined: Fri Jun 18, 2004 3:04 am

Post by tores »

My version is 4.3.7.

I should use "sekvens" as a ordinary global? Not as a member of the class?
contact_bogomil
Forum Newbie
Posts: 22
Joined: Mon May 27, 2002 8:13 am
Location: Sofia, Bulgaria
Contact:

Post by contact_bogomil »

Yes just try make it global and use it by this way.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

I think you need to post the code you have for declaring verkans in the class..
tores
Forum Contributor
Posts: 120
Joined: Fri Jun 18, 2004 3:04 am

Post by tores »

This is the code declaring the class-variables

Code: Select all

<?php
class parser{
  var $ordrenummer, $linje, $artikkel, $perSingelTrommel, $ID, $sekvens; 

?>
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

I believe, by sending the "parser" name as part of the callback, php creates a new object, then calls the callback function. Try replacing "parser" with &$this
Post Reply