Link to home
Start Free TrialLog in
Avatar of Blixtsystems
Blixtsystems

asked on

PHP script dying...why?

I have a function looking like this:

function remove_tree($tid){
    $Q = "DELETE FROM tree WHERE Id = $tid";
    $R = mysql_query($Q);
    $Q2 = "SELECT * FROM tree_member WHERE tree_id = $tid";
    $R2 = mysql_query($Q2);
    while($rec = mysql_fetch_object($R2)){
        echo "deleting indi:".$rec->individual_id;
        del_indi($rec->individual_id, 1);
    }
    echo "OK";
}

As long as I comment out the call to del_indi everything is ok, but when the call is in there the script never reaches the echo "OK".
I have tried with commenting out everything inside the del_indi function which otherwise is working ok when called directly, but still the issue remains, the script will stop executing as long as the call is there.

The del_indi function is now looking like this:

function del_indi($id, $silent) {
    echo "deleting:".$id;
}

I never recive the echo from del_indi.
The MySQL statements is working ok (the correct row in table "tree" is deleted and echo "deleting indi" returns the right id).

PHP Version is 5.1.2
ASKER CERTIFIED SOLUTION
Avatar of glcummins
glcummins
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Blixtsystems
Blixtsystems

ASKER

There used to be code in there, but I stripped it out for testing for now.

I made an even more stripped down version:

      function main(){
            echo "main";
            //test();
            echo "OK";
      }
      function sub(){
            echo "sub";
      }

That will return "mainOK"

However:

      function main(){
            echo "main";
            test();
            echo "OK";
      }
      function sub(){
            echo "sub";
      }

will return only "main"

The functions is inside a class instantiated in engine.php like this:

require_once('classes/engine.class.php');
$engine = new engine();
$engine->main();
Sorry that should be:

      function main(){
            echo "main";
            sub();
            echo "OK";
      }
      function sub(){
            echo "sub";
      }

Result is the same however
ok...I figured it was a scope issue of some sort and is used to having the scope of the class accessible inside the function.
But apparently I need a $this->sub()
SOLUTION
Avatar of Jeff Darling
Jeff Darling
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
It was simply a scope issue like I explained above.
Since I'm new to this site I'm not sure what to do when I solved the issue myself, so I'll just give you guys the points for your effort.
Thanks