Discover millions of ebooks, audiobooks, and so much more with a free trial

Only $11.99/month after trial. Cancel anytime.

Introduction to PHP, Part 4, Second Edition
Introduction to PHP, Part 4, Second Edition
Introduction to PHP, Part 4, Second Edition
Ebook94 pages44 minutes

Introduction to PHP, Part 4, Second Edition

Rating: 0 out of 5 stars

()

Read preview

About this ebook

The book describes: classes (continuation of the Part 2 and Part 3), interfaces, traits, tuples, namespaces, ADT, randomizing, HTML, PHP & JavaScript intermixing.

LanguageEnglish
PublisherAdam Majczak
Release dateMar 1, 2015
ISBN9781311858832
Introduction to PHP, Part 4, Second Edition

Read more from Adam Majczak

Related to Introduction to PHP, Part 4, Second Edition

Related ebooks

Programming For You

View More

Related articles

Reviews for Introduction to PHP, Part 4, Second Edition

Rating: 0 out of 5 stars
0 ratings

0 ratings0 reviews

What did you think?

Tap to rate

Review must be at least 10 words

    Book preview

    Introduction to PHP, Part 4, Second Edition - Adam Majczak

    Introduction to PHP

    Part IV

    Adam Majczak

    C. Adam Majczak, 2015, All Rights Reserved

    Smashwords: Second English Edition

    (improved and updated)

    E-Edition, License Notes

    This e-book is licensed for your personal use only. This e-book may not be re-sold or given away to others. To share this book with another person, please purchase an additional copy for each recipient.

    While every precaution has been taken in the preparation of this book, the publisher and the author assume no responsibility for errors or omissions, or any for damages resulting from any use of the information contained herein.

    ENGLISH EDITION

    PART IV

    CONTENTS:

    Let’s take a look again (without HEREDOC)

    CHAPTER 11: Classes, objects and traits in use

    Generating HTML page using PHP classes

    A few words about PHP scope

    Interfaces

    Abstract data types (ADT) and the abstract keyword

    Polymorphism

    Traits

    Randomized numbers and strings

    CHAPTER 12: Intermixing PHP and HTML, JavaScript, OS commands

    Intermixing PHP and HTML

    Using intermixed PHP and JavaScript codes

    How to transfer data from PHP variable to JavaScript variable?

    How to transfer data from JavaScript variable to PHP variable?

    PHP intermixing with JavaScript, how it works?

    Transferring data from PHP variables to JavaScript again

    PHP interaction with operating system and file system

    Pointing to an external process

    Basic file-related functions

    CHAPTER 13: Effective programming using functions and classes

    Algorithm complexity and recursive functions

    Fibonacci sequence and factorials

    Programming errors

    The is_datatype() group

    Better encapsulation: using __set() and __get() methods

    Property and function overloading

    More about lambda functions and closures

    Namespaces

    Namespace aliases

    CHAPTER 14: A few advanced topics simply explained

    A few words about error handling

    Function call - time measuring

    The NaN and Infinity errors

    Exception handling

    Shared operating memory in PHP

    A few words about data encryption in PHP

    Tuples in PHP

    Let’s take a look again (without HEREDOC)

    Let’s take a look at the previous example again to compare it with a new object-oriented version shown later.

    Generating HTML page using PHP functions

    (PHP code from the Part III repeated, excluding HEREDOC constructions used in previous version)

    date_default_timezone_set('UTC');

    // Generates the top of the page

    function addHeader($page, $title) {

    $page .= "$title

    center\">$title

    ;

    return $page;

    }

    // Generates the bottom of the page

    function addFooter($page, $year, $copyright) {

    $page .= "

    © $year $copyright

    ";

    return $page;

    }

    // Initialize the page variable

    $page = '';

    // Add the header to the page

    $page = addHeader($page, 'Adam Majczak: PHP Script');

    // Add something to the body of the page

    $page .=

    This page was generated with a PHP script

    ;

    // Add the footer to the page

    $page = addFooter($page, date('Y'), ' Adam Majczak.');

    // Display the page

    print $page;

    ?>

    // printout:

    Adam Majczak: PHP Script

    This page was generated with a PHP script

    © 2015 Adam Majczak.

    This simple code generates the following HTML code:

    Adam Majczak: PHP Script

    center>Adam Majczak: PHP Script

    center>This page was generated with a PHP script

    center>© 2013 Adam Majczak.

    looking at a client browser window like this:

    Pic. 16. The code in action (client browser).

    CHAPTER 11: Classes, objects and traits in use

    Generating HTML page using PHP classes

    HTML codes can be generated using PHP functions or using PHP classes and objects. It is the time for a short review of PHP classes and objects in use. In the previous Chapter

    Enjoying the preview?
    Page 1 of 1