Note that there are some explanatory texts on larger screens.

plurals
  1. POHow are functions executed in a class
    primarykey
    data
    text
    <p>This may be a simples question but i couldn't find the answer..</p> <p>If i have a class and declare the value of a variable within a function being called from a while statement and then use that variable later in another function when does that variable get changed to the next value in the array?</p> <p>ie.. I know that php executes code form top to bottom, but is that true with classes and functions being called from with in another function. Does php wait to go to the next item in the while statement until all functions and sub functions have been called or does it call a function then move to the next item in the list??</p> <pre><code>class myClass{ public $cust; function __construct(){ $sql = mysql_query("SOME QUERY"); while($row = mysql_fetch_array($sql)){ myClass::sendEmail(); } } function sendEmail(){ $this-&gt;cust = new selectDatabase(); $this-&gt;cust-&gt;table = "customer_main"; $this-&gt;cust-&gt;where = " WHERE customerID = '".$customerID."' "; $this-&gt;cust-&gt;getItems(); $this-&gt;cust-&gt;name = $name; $this-&gt;cust-&gt;email = $email; $sql = mysql_query("SELECT EmailTo, EmailFrom, EmailSubject, EmailBody FROM system_email"); $row = mysql_fetch_assc($sql); $to = myClass::dbReplace($row['EmailTo']); $From = myClass::dbReplace($row['EmailFrom']); $subject = myClass::dbReplace($row['EmailSubject']); $body = myClass::dbReplace($row['EmailBody']); $headers = "From: ".$from." \r\n"; $headers .= "Content-type: text/html\r\n"; $headers .= "Bcc: stoneops@cornell.edu\r\n"; $headers .= "X-Mailer: PHP/" . phpversion(); mail( $to, $subject, $body, $headers); } private function dbReplace($thisStr){ $x = substr_count($thisStr,"DB["); $z = 0; $holdArry = array(); while($z &lt; $x){ $rplStr = genEmail::findSubStr($thisStr); $t = substr_count($thisStr, "DB[".$rplStr."]"); $rplStr2 = split(':', $rplStr); $thisStr = str_replace("DB[".$rplStr."]", $this-&gt;{$rplStr2[0]}-&gt;{$rplStr2[1]}, $thisStr); $z = $z +$t; } return $thisStr; } private function findSubStr($str){ $pos = strpos($str, 'DB['); // outputs ER@EXAMPLE.com $pt1 = substr($str, ($pos + 3) ); $pos = strpos($pt1, ']'); $pt2 = substr($pt1, -1 * strlen(substr($pt1, $pos))); $pt2 = str_replace($pt2, "", $pt1); return $pt2; } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload