Good Morning,

I am working on a script that requires multiple embedded function calls that could go up to 5 levels deep

My Question is this...
I need to be able to use the accumulating variables from function D outside of all the functions to display data.

if I have 2 variables unique to each function, because they are accumulating different values, do I need to define them as global in each of the preceeding functions?

<?php
            functionA( ){
                global $a1, $a2, $b1, $b2, $c1, $c2, $d1, $d2;
                // function code ...
                if $a1==$a2{
                  functionB( );
                }
            }
            functionB( ){ // called from function A as well as other places
                global $b1, $b2, $c1, $c2, $d1, $d2;
                // function code ...
                if $b1==$b2{
                  functionC( );
                }
            }
            functionC( ){ // called from function B as well as other places
                global $c1, $c2, $d1, $d2;
                // function code ...
                if $c1==$c2{
                  functionD( );
                }
            }
            functionD( ){ // called from function C as well as other places
                global $d1, $d2;
                //  function code...
            }
    ?>    

I currently have it laid out like this, but the values are not being accumulated as expected... the variables have no values to them.

I hope this question makes sense, but if not please tell me what else you need to know to be able to answer the question...

thanks
Douglas

Recommended Answers

All 2 Replies

Member Avatar for iamthwee

It's a terrible way to work...

Consider revising your code. This is what OOP is for.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.