Card Set Information

2013-11-01 08:20:54

Show Answers:

  1. What is an array?
    An array is a special variable, which can hold more than one value at a time.
  2. What is an associative array?
    Associative arrays are arrays that use named keys that you assign to them.
  3. Get The Length of an Array
    echo count($array_name);
  4. Create a simple array
  5. How does Switch works?
    • $favcolor="red";
    • switch ($favcolor)
    • {
    • case "red":
    •   echo "Your favorite color is red!";
    •   break;
    • case "blue":
    •   echo "Your favorite color is blue!";
    •   break;
    • case "green":
    •   echo "Your favorite color is green!";
    •   break;
    • default:
    •   echo "Your favorite color is neither red, blue, or green!";
    • }
  6. Start a session
  7. Storing a Session Variable
  8. Delete a session variable
  9. Destroy a session
  10. Magic Methods
    • The constructor is a magic method that gets called when the object is
    • instantiated. It is usually the first thing in the class declaration
    • but it does not need to be, it a method like any other and can be
    • declared anywhere in the class. Constructors also inherit like any
    • other method. So if we consider our previous inheritance example from
    • the Introduction to OOP, we could add a constructor to the Animal class
    • like this:

    • class Animal{
    • public function __construct() {
    • $this->created = time();
    • $this->logfile_handle = fopen('/tmp/log.txt', 'w');
    • }
    • }
  11. Magic constants

    The current line number of the file.
  12. __FILE__
    The full path and filename of the file. If used inside an include, the name of the included file is returned. Since PHP 4.0.2, __FILE__ always contains an absolute path with symlinks resolved whereas in older versions it contained relative path under some circumstances.
  13. __FILE__
  14. __DIR__
    The directory of the file. If used inside an include, the directory of the included file is returned. This is equivalent to dirname(__FILE__). This directory name does not have a trailing slash unless it is the root directory. (Added in PHP 5.3.0.)
  15. __FUNCTION__
    The function name. (Added in PHP 4.3.0) As of PHP 5 this constant returns the function name as it was declared (case-sensitive). In PHP 4 its value is always lowercased.
  16. __CLASS__
  17. __CLASS__
    The class name. (Added in PHP 4.3.0) As of PHP 5 this constant returns the class name as it was declared (case-sensitive). In PHP 4 its value is always lowercased. The class name includes the namespace it was declared in (e.g. FooBar). Note that as of PHP 5.4 __CLASS__ works also in traits. When used in a trait method, __CLASS__ is the name of the class the trait is used in.
  18. Can we use a function with the same name as the class to replace  __construct ?
    • A function becomes a constructor, when
    • it has the same name as the class. If a class
    • has no constructor, the constructor of the base class will be
    • called, if it exists.
  19. What is scope ?
    A variable scope is the 'space' where we can retrieve it's value.
  20. What is PDO?
    • PDO (PHP Data Objects) é uma extensão que fornece uma interface padronizada para trabalhar com bancos de dados, cuja finalidade é
    • abstrair a conexão e interações com os bancos, ou seja, independente do
    • banco de dados que estiver sendo utilizado os métodos executados serão
    • os mesmos, mas isso não significa que seu sistema será portável entre
    • diversos bancos de dados, por mais que o uso do PDO facilite a
    • portabilidade, esta interface significa apenas que você se comunicará
    • com qualquer banco de dados através de um determinado conjunto de
    • métodos e classes.
  21. ???

    The request string is everything following the '?' in the URL.
  22. ??~?

    shifts the first value of the array off and returns it, shortening the array by one element and moving everything down. All numerical array keys will be modified to start counting from zero while literal keys won't be touched.

    • <?php
    • $stack = array("orange", "banana", "apple", "raspberry");$fruit = array_shift($stack);
    • print_r($stack);
    • ?>
  23. ???

    To represent (an abstract concept) by a concrete or tangible

    example: "Two apples ... both instantiate the single universal redness"
  24. ???

  25. ???
    inline PHP tags
  26. Regular expression

    A regular expression (regex or regexp for short) is a special text string for describing a search pattern. You can think of regular expressions as wildcards on steroids. You are probably familiar with wildcard notations such as *.txt to find all text files in a file manager. The regex equivalent is .*.txt$.
  27. if shortcut
    $var = 5;$resultado = ($var > 2 ? true : false);print_r($resultado); // 1

    $is_admin = ($user['permissions'] == 'admin' ? true : false);

    echo 'Welcome '.($user['is_logged_in'] ? $user['first_name'] : 'Guest').'!';
  28. Namespaces

    • What are namespaces? In the broadest definition namespaces are a way of encapsulating
    • items. This can be seen as an abstract concept in many places. For example, in any
    • operating system directories serve to group related files, and act as a namespace for
    • the files within them. As a concrete example, the file foo.txt can
    • exist in both directory /home/greg and in /home/other,
    • but two copies of foo.txt cannot co-exist in the same directory. In
    • addition, to access the foo.txt file outside of the
    • /home/greg directory, we must prepend the directory name to the file
    • name using the directory separator to get /home/greg/foo.txt. This
    • same principle extends to namespaces in the programming world.

    • In the PHP world, namespaces are designed to solve two problems that authors
    • of libraries and applications encounter when creating re-usable code elements
    • such as classes or functions:

    • Name collisions between code you create, and
    • internal PHP classes/functions/constants or third-party classes/functions/constants.

    • Ability to alias (or shorten) Extra_Long_Names designed to alleviate the first problem,
    • improving readability of source code.

    • PHP Namespaces provide a way in which to group related classes, interfaces,
    • functions and constants. Here is an example of namespace syntax in PHP:

    Example #1 Namespace syntax example

    • <?php
    • namespace myname// see "Defining Namespaces" section

    • class MyClass {}
    • function myfunction() {}
    • const MYCONST 1;

    • $a = new MyClass;
    • $c = new mynameMyClass// see "Global Space" section

    • $a strlen('hi'); // see "Using namespaces: fallback to global
    •                    // function/constant" section

    • $d = namespaceMYCONST// see "namespace operator and __NAMESPACE__
    •                         // constant" section
    • $d __NAMESPACE__ 'MYCONST';
    • echo constant($d); // see "Namespaces and dynamic language features" section
    • ?>
  29. <?phpclass Controller {    public function __construct() {        $arr = array("a","b","c");        $myView = new View($arr);    }}class View {    private $content;    public function __construct($content) {        $this->content = $content;        include_once('myPage.inc.html');    }}?>
    <?phpclass Controller {    public function __construct() {        $arr = array("a","b","c");        $myView = new View($arr);    }}class View {    private $content;    public function __construct($content) {        $this->content = $content;        include_once('myPage.inc.html');    }}?>