PLC report


Session 1 – Introduction

  • Acronym of Hypertext Preprocessor
  • Created by Rasmus Lerdorf in 1994
  • Often related with web development
  • HTML-embedded scripting
  • Many syntax derived from C, Java, Perl.
  • Website :
  • The benefit of using PHP:
    • It’s free
    • Easy yet efficient
    • Dynamic
    • Runs on many platforms
    • Compatible with most recent servers
    • Supports variety of databases
    • Very secure
  • PHP abilities:
    • Generate dynamic page content
    • Manipulate files on servers
    • Manipulate data in database
    • Send and receive cookies
    • Can control user-access
    • Encrypt data
  • A lot of websites use PHP, such as facebook, tumblr, Wikipedia, wordpress, google, digg, etc.


Session 2 – Language, Syntax, Semantics

  • Syntax : form / arrangement of sentences
  • Semantics : meaning of sentences
  • The terminology:
    • Token : Classification of lexeme
    • Lexeme : Symbols or set of characters
    • Pattern : Rule for Lexeme to be in Token
  • To initiate the PHP, it can be done in two ways:
    • In a separate file, which force server to parse and run html as php script
    • Inside HTML, which is usually between body tag. The tag to open and close php is:
      • Canonical (<?php … ?>)
      • Short-open (<? … ?>)
      • HTML Script (<script language=”php” … ?>)
      • ASP-Style (<% … %>)
      • Script tag and ASP-style tag has been removed from php since php7
    • Syntax rule in php:
      • Always end with a semicolon ( ; )
      • User defined functions, classes, core languages are case-insensitive
      • Variables are no exception case-sensitive
      • Whitespace insensitivity
    • Comment syntax
      • Single line (using // or #)
      • Multi line (using /* … */)

Session 3 – Variable

  • Etymology : Latin word variābilis (able to change)
  • In programming, is a storage location for an information (value)
  • Six important properties
    • Name
      • Represents the title of the information in the variable, symbolic
      • In PHP, there’s no limit in length
      • Suggested that every variable should have an unique name
    • Type
      • Represents what kind of data stored within the variable.
      • Data type includes:
        • String
        • Integer
        • Float / Double
        • Boolean
        • Array
        • Object
        • NULL
        • Resource
      • Value
        • A variable value changes over time
        • Value in variable should be declared
        • Else, default value will be used (depends on the language used)
      • Scope
        • A context within which It is defined.
        • Three different variable scopes:
          • Global
            • A variable stated can be used in any part of the program
            • Usually declared outside a function
            • Ways to access global variables
              • Call it the way like usual
              • In a function:
                • Use global keywords
                • Use $GLOBALS[] array
              • Local
                • A variable stated can be used ONLY in a relevant function.
                • Declared in a function
                • Way to access it is by calling the function
              • Static
                • A local variable will lose its value after a function is executed or leaves the scope
                • To prevent this from happening, we use static scope
                • By using static keyword
              • Lifetime
                • The period in which the variable or object has valid memory
                • Three types of lifetime
                  • Static
                  • Automatic
                  • Dynamic
                • Location (memory)
                  • Variable and its value contained in variable will be stored by the compiler
                  • Different data type uses different memory size
                • Tips on declaring variable
                  • Often in programming language, declaring a variable must starts with a letter
                  • Using number in variable naming is allowed
                  • A variable name can’t have space nor special character
                  • In substitute of space, use underscore ( _ )
                  • Depends on the situation, declare the name wisely.
                • Variable declaring in PHP:
                  • Always starts with $ followed by the name
                  • Name must start with a letter or the underscore (thus means, can’t start with a number)
                  • Name only contain alpha-numeric characters and underscore (no special character)
                  • Case Sensitive
                  • No need to declare data type


Session 4 – Data Type

  • In PHP, the supported data type are:
    • String
      • A sequence of characters
      • A string can be any text inside quotes
      • Can use single or double quotes
    • Integer
      • Non-decimal number
      • Range between – 2,147,483,648 and 2,147,483,647
      • Rules for integer:
        • An integer must have at least one digit
        • An integer must not have a decimal point
        • An integer can be either positive or negative
        • Integers can be specified in three formats: decimal (10-based), hexadecimal (16-based – prefixed with 0x) or octal (8-based – prefixed with 0)
      • Float (floating point numbers – also called double)
        • Number with a decimal point or a number in exponential form
      • Boolean
        • Represents two possible states : TRUE or FALSE
      • Array
        • An array stores multiple values in one single variable
        • It can be one-dimension, two-dimension, or even more, by adding the needed indices
      • Object
        • An object is a data type which stores data and information on how to process that data.
        • Must be explicitly declared
        • It is necessary to declare a class of object
      • NULL
        • A special data type which can only have one value, which is NULL
        • Is a variable that has no value assigned to it
      • Resource
        • The special resource type is not an actual data type. It is the storing of a reference to functions and resources external to PHP.
        • A common example of using the resource data type is a database call.


Session 5 – Expression & Assignment

  • Arithmetic Expressions
    • Consists of mathematical equations, following the rule PEMDAS.
    • Based on its number of operands:
      • Unary has one operand
      • Binary has two operands
      • Ternary has three operands
    • Binary expression can be combined with ternary
  • Type Conversions
    • Consists of narrowing and widening
      • Narrowing, if the data type cannot include all the value of the original type
        Ex: float to int
      • Widening, if the data type can include all the value of the original type
        Ex: int to float
    • Explicitly can be done, in PHP, by using this syntax:
      <var1> = <datatype>(<var2>);
  • Relational Expressions
    • Consists of relational operators, such as
      • Equal ( == )
      • Not equal ( <> )
      • Bigger than ( > )
      • Smaller than ( < )
    • The result is in boolean (1 / 0)
  • Logical Expressions
    • Consists of logical operators, such as
      • And ( && )
      • Or ( || )
      • Xor
      • Not ( ! )
      • ( && || ) has a higher priority on precedence than ( and or )
    • Bitwise Expressions
      • Consists of bitwise operators, such as
        • & (and)
        • | (or)
        • ^ (xor)
        • ~ (not)
        • << (shift left)
        • >> (shift right)
      • Assignment Statement
        • Usually done by following this syntax:
          <var> <assign_op> <exp>
        • In PHP, we use equal sign ( = ) as our assign operator.
        • Assigning value can be done in unary, binary, and ternary.
        • Multiple assignments in PHP are possible.


Session 6 – Control Structure Statements

  • By definition, it’s a control statement and the statements whose execution it controls
  • Divided into two
    • Selection statements
      • Executes a group of statement if and only if one requirement is met.
      • Divided into :
        • Two-way selection statements
          • Uses if else variations:
            • If … then … (If)
            • If … then … else … (If else)
          • Syntax in PHP :
            if (condition)

{statements if condition(s) are met;}
else {statements if condition(s) are not met;}

  • The difference between if and if else statement is that when the conditions are not met, if statement will just break from the selection. This also can be done in if else statement by using break; as their output when the condition are not met
  • In some language, they use then after if (, for example)
  • Multiple-way selection statements
    • Uses switch case and if elseif else statement
      • If … then … elseif … else … (if elseif else) has a similar syntax to if else.
      • Switch case lists all possible value of a variable (generally programmer-defined) and executes the statement contained only if the value matches.
      • Syntax for if elseif else

if (condition) {

code to be executed if this condition is true;

} elseif (condition) {

code to be executed if this condition is true;

} else {

code to be executed if all conditions are false;


  • It is possible to add more elseif, thus adding more and more ways.
  • Syntax for switch case

switch (n) {

case label1:

code to be executed if n=label1;


case label2:

code to be executed if n=label2;


case label3:

code to be executed if n=label3;



code to be executed if n is different from all labels;


  • Iterative statements
    • Technically speaking, it’s a loop (repeating action)
    • Divides into:
      • Counter-controlled loop
        • Using counter as a condition
        • Also known as “for”
        • Syntax:
          for (init counter; test counter; increment counter) {
          code to be executed;
          desc : init for initialization (var. starting value)
          test counter : condition of the counter to be met to repeat
          increment counter : increase the loop counter value. Note that using decrement is also possible.
      • Logically controlled loop
        • Pretest execution
          • The conditions are done before condition checking and repeat if the condition(s) are met.
          • Known as “Do While”
          • Syntax :
            do {
            code to be executed;
            } while (condition is true);
        • Posttest execution
          • The conditions are done after condition checking and repeat if the condition(s) are met.
          • Known as “While”
          • Syntax :
            while (condition is true) {
            code to be executed;
        • The difference between pretest and posttest execution is that pretest execution executes the statement(s) AT LEAST once, while posttest execution may not executes at all. This is caused by the time of condition checking.
      • It is possible for these statements to be nested, that is, a compounded statement inside a statement.


Session 7 – Subprograms

  • By definition, is a part of a whole program that can work semi-independently.
  • To activate the subprogram, the main function has to call the subprogram.
  • Has three characteristics:
    • Each has a single entry point
    • There can be only one subprogram executed at any given time
    • When the subprogram terminated, it returns a value to the caller
  • In php, the syntax is:
    • To declare
      function funct_name(parameter)
      {instructions go here, between the braces }
    • To call
  • Variable in a subprogram
    • Its local is scope
    • Its lifetime is limited only during the execution of the subprogram
    • It is possible to make the variable in a subprogram has a global scope by adding global keyword (in PHP)
  • Local Referencing Environments
    • Can be stack-dynamic
      • Advantages
        • Support for recursion
        • Storage for locals is shared among some subprograms
      • Disadvantages
        • Allocation/de-allocation, initialization time
        • Indirect addressing
        • Subprograms cannot be history sensitive
      • Can be static, with its advantages and disadvantages are the opposite of stack-dynamic’s
    • Parameter-Passing Methods
      • Has three semantic models
        • In mode : Receive data from the corresponding actual parameter
        • Out mode : Transmit data to the actual parameter
        • In-out mode : Combination of in mode and out mode
      • Ways of transmitting data has two conceptual models
        • Physically move the actual value
        • Transmit the access path (usually pointer)
      • Pass by Value
        • The value of the actual parameter is used to initialize the corresponding formal parameter, which then acts as a local variable of the subprogram
        • Needs additional storage for the formal parameter
      • Pass by Result
        • No value transmitted to the subprogram
        • The value is transmitted back to the caller’s actual parameter before the control is transferred back to the caller
        • May cause parameter collision to one another
      • Pass by Value Result
        • Combination of pass by value and pass by result
        • Has a disadvantage of both passing method mentioned
        • The actual values are copied, unlike pass by result. Hence, the name pass by copy is also known for this passing method
      • Pass by Reference
        • Transmits an access path to the called subprogram, usually an address
        • More efficient in both time and space
        • Disadvantages:
          • Access to formal parameters are slow
          • Inadvertent and erroneous changes may be made to the actual parameter
          • Aliases can be created
        • Pass by Name
          • The actual parameter is textually substituted for the corresponding formal parameter in all its occurrences in the subprogram
          • A formal parameter is bound to an access method at the time of the subprogram call, but the actual binding to a value or an address is delayed until the formal parameter is assigned or referenced
          • Not used in any widely used language
        • Subprogram Name as Parameter
          • Occurs if nested subprogram happens
          • Three referencing environment:
            • Shallow binding : It’s the environment of the call statement that enacts the passed subprogram
            • Deep binding : It’s the environment of the definition of the passed subprogram
            • Ad hoc binding : It’s the environment of the call statement that passed the subprogram as an actual parameter (has never been used)
          • Overloaded Subprograms
            • Is a subprogram that has the same name as another subprogram in the same referencing environment
            • If overloaded subprogram occurs, it must have an unique protocol (parameters and the return value)
          • Generic Subprograms
            • Generic (polymorphic) subprogram takes parameters of different types on different activations
            • Overloaded subprograms provide ad hoc polymorphism
            • A subprogram that takes a generic parameter that is used in a type expression that describes the types of the parameters of the subprogram provides parametric polymorphism
          • Control State
            • Closure is basically a subprogram with some variables that persist between function calls
            • Coroutine is a subprogram that save control state between calls


Session 8 – Abstract Data Type

  • An abstraction is a view or representation of an entity that includes only the most significant attributes
    • The representation of objects of the type is hidden from the program units that use these objects, so the only operations possible are those provided in the type’s definition
    • The declarations of the type and the protocols of the operations on objects of the type are contained in a single syntactic unit. Other program units are allowed to create variables of the defined type.
  • The concept of abstraction is fundamental in programming (and computer science)
  • Nearly all programming languages support process abstraction with subprograms
  • Nearly all programming languages designed since 1980 support data abstraction
  • The Advantage of Data Abstraction:
    • Advantages the first condition
      • Reliability–by hiding the data representations, user code cannot directly access objects of the type or depend on the representation, allowing the representation to be changed without affecting user code
      • Reduces the range of code and variables of which the programmer must be aware
      • Name conflicts are less likely
    • Advantages of the second condition
      • Provides a method of program organization
      • Aids modifiability (everything associated with a data structure is together)
      • Separate compilation
    • In PHP, this can be done by making class abstraction or methods
      • Classes defined as abstract may not be instantiated, and any class that contains at least one abstract method must also be abstract
      • Methods defined as abstract simply declare the method’s signature – they cannot define the implementation


Session 9 – Object-Oriented Programming

  • Three major language features:
    • Abstract data type (Session 8)
    • Inheritance
      • Productivity increases can come from reuse
      • ADTs are difficult to reuse—always need changes
      • All ADTs are independent and at the same level
      • Inheritance allows new classes defined in terms of existing ones, i.e., by allowing them to inherit common parts
      • Inheritance addresses both of the above concerns–reuse ADTs after minor changes and define classes in a hierarchy
    • Polymorphism (Session 7)

Author: Nicholaus Hendrik

He / Him | Not your basic urban pianist | BBN01 / Binusian2020 | Board Game Enthusiast | Cursive Writer | ID/EN/IT*/RU*/FR*

Leave a Reply

Your email address will not be published. Required fields are marked *