*** NOTE: I may add to this post
    after the Week 9 Labs!!! ***
=====
CS 328 - Week 9 Lecture 1 - 2025-03-24
=====

=====
TODAY WE WILL
=====
*   announcements
*   APPLICATION TIER: starting intro to PHP
*   start introducing PHP basics
*   prep for next class

=====
*   should be working on Homework 7
    *   at least first attempts due by 11:59 pm on Friday, March 28
    *   submit files early and often!

*   watch for class email when zyBooks Chapter 5 - PHP Fundamentals
    is available

*   note the posted recordings on CSS flexbox and grid layouts
    on Canvas, in the section "Class Recordings"

=====
intro to PHP
=====
*   goal: a useful subset of PHP to get you started creating
    small web applications that use the Oracle student database

    *   to use PHP on the application tier!

*   created by Rasmus Lerdorf in 1994

    *   originally: stood for "Personal Home Page"

    *   but ... after many expansions ... then changed to
        stand for:    PHP: Hypertext Preprocessor

                      ^ yes, that's a recursive acronym

*   PHP is free to use,
    ships with the Apache web server,
    is one of NUMEROUS choices for application-tier programming

    You can embed PHP within HTML

    BUT: the PHP is executed ON THE APPLICATION TIER.

*   Much of its syntax is borrowed from C, Java, and Perl (!),
    with some PHP-particular features thrown in;

*   typically, you put your PHP in a file whose suffix is .php
    *   whether it is a file of PHP functions,
        or HTML code with PHP embedded within it

    1. when a client-tier browser requests a document with
       suffix .php

    2. the WEB SERVER on the application tier directs that
       request (and any accompanying name=value pairs, if this
       action is a form submission) to the PHP ENGINE also running
       on the application tier

    3. The PHP Engine executes the PHP in the requested document,
       possibly using the accompanying data, on the application tier

    4. ...and returns the result (which now contains no PHP)
       to the WEB SERVER

    5. ...and the WEB SERVER returns that response to the CLIENT
       browser

    6. ...and the CLIENT browser typically DISPLAYS the returned
       result.

    *   the client tier should see NO PHP!!!
        just the results of EXECUTING the PHP
	(because the PHP is executed on the APPLICATION TIER)

=====
*   on an application tier terminal,
    php -version

    ...will let you see your version of PHP

*   see the posted PHP references page!
    *   NOTE that the PHP home page -- php.net
        and the PHP manual https://www.php.net/manual/en/
	are USEFUL references

=====
the TWO kinds of PHP tags we'll be using in CS 328:
=====
*   regular PHP tag

    <?php
        PHP_statement;
	PHP_statement;
	...
	PHP_statement;
    ?>

    *   these statements are executed by the PHP preprocessor

*   PHP expression tag

    <?= desired_PHP_expr ?>

    *   you should embed a single PHP expression
        (simple or compound, that has a value)

    *   when executed, the value of this expression
        will replace this expression tag in the executed
	result

*   and class style: your PHP should be within either
    regular PHP tags or PHP expression tags

=====
PHP comments - *** these MUST be in a PHP tag! ***
=====

/* I am a multi
   line
   comment */

// I am a single line comment

# this is also a single-line comment

=====
some PHP basic types
=====
*   loosely typed -- every expression has a type,
    but a variable's type will be type of its value...

*   four scalar data types:
    integer
    float
    string
    boolean

*   two non-scalar data types:
    arrays
    objects

*   and several others -- for example, two others are:
    *   null  <-- yes, it IS a type, and ALSO a value...!

        the null type only has one value, null...! (and not
	case sensitive, so can also be NULL, null, Null...)

    *   resource - a special variable holding a reference to
        an external resource (like an opened file, database
	connection, and more...)

*   integers are what you probably expect;
*   float - can also be called double, real
*   boolean - true, false
    *   but keywords in PHP are not case-sensitive,
        so TRUE and False and etc. are also OK

    *   if you use a non-boolean value in a boolean context,
        PHP will try to treat it as a boolean!

        these are all considered to be false:
	*   false
	*   the integer 0
	*   the float values 0.0 and -0.0
	*   the empty string "" '' and the string "0" '0'
	*   an array with zero elements
	*   the unit type NULL (including unset variables)
	*   and a few others..

        But other values are considered to be true,
        including resources and NAN <- not-a-number

*   string - can be in single or double quotes
    (BUT there are some interesting differences between these
    if there is a variable in that string...)

*   array - both indexed and associative arrays

*   object - encapsulation of state and behavior
    *   PHP does support classes

=====
compound expressions
=====
*   usual collection of infix and prefix operations,
    and function calls, and a bit more,
    with some distinctively-PHP twists;

*   function call:

    funct_name(arg, arg)

    some built-in functions:
    *   var_dump(desired_variable) will output the data type of
        a variable

    *   is_blah (is_int, is_float, is_bool, others)
        return a bool letting you know if its argument is of that type

    *   gettype expects one argument and returns a string
        whose contents are the name of the type of its argument

======
PHP variable
=====
*   STARTS with $, followed by a character (CANNOT be a digit),
    followed by 0 or more letters, digits, or underscores

*   and you can assign to a variable with the assignment
    operator, =

$name = "Ginger";
$quant = 40.5;

*   once you create, its scope is the rest of that PHP document --
    you can use it in any of the PHP tags from when it is created
    until the end of that .php file