70 likes | 217 Views
More PHP…. Understanding Variable Scope. The term scope refers to the places within a script where a particular variable is visible. The six basic scope rules in PHP are as follows : Built-in superglobal variables are visible everywhere within a script.
E N D
Understanding Variable Scope • The term scope refers to the places within a script where a particular variable is visible. The six basic scope rules in PHP are as follows: • Built-in superglobal variables are visible everywhere within a script. • Constants, once declared, are always visible globally; that is, they can be used inside and outside functions. • Global variables declared in a script are visible throughout that script, but not inside functions. • Variables inside functions that are declared as global refer to the global variables of the same name. • Variables created inside functions and declared as static are invisible from outside the function but keep their value between one execution of the function and the next. • Variables created inside functions are local to the function and cease to exist when the function terminates.
PHP Simple eCommerce • Bob’s Auto Parts… • Retrieve HTTP_POST • Quick sanity check - if ($totalqty == 0) • Date() Function • Conditional Statement • Define() constant variables • Operator Precedence (calc tax rate) • Why would this NOT work in an actual business?
PHP while Loops • Freight calculator… • Static vs dynamic table generation. • Which way is better? Why?
PHP Better eCommerce… • Same as Simple, BUT… • With a flat file we can record orders and view them later. • Some rants about flat files • Security! Is the setup that I have currently secure? • PHP File system Functions (http://us.php.net/manual/en/ref.filesystem.php) • fopen(), flock(), fwrite(), fclose(), fgets(), fgetss(), fgetcsv(), feof()
PHP Better eCommerce • What are some of the issues with using a flat file? • Is there a time where flat files would be good to use? • Is there anything better?
Mid Term Review • HTML • CSS • JavaScript • PHP