Share this?

PHP as in Wikipedia

alt

This is a wikipedia post on PHP

PHP is a general-purpose programming language originally designed for web development. It was originally created by Rasmus Lerdorf in 1994;[5] the PHP reference implementation is now produced by The PHP Group.[6] PHP originally stood for Personal Home Page,[5] but it now stands for the recursive initialism PHP: Hypertext Preprocessor.[7]

PHP code may be executed with a command line interface (CLI), embedded into HTML code, or used in combination with various web template systems, web content management systems, and web frameworks. PHP code is usually processed by a PHP interpreter implemented as a module in a web server or as a Common Gateway Interface (CGI) executable. The web server outputs the results of the interpreted and executed PHP code, which may be any type of data, such as generated HTML code or binary image data. PHP can be used for many programming tasks outside of the web context, such as standalone graphical applications[8] and robotic drone control.[9]

The standard PHP interpreter, powered by the Zend Engine, is free software released under the PHP License. PHP has been widely ported and can be deployed on most web servers on almost every operating system and platform, free of charge.[10]

The PHP language evolved without a written formal specification or standard until 2014, with the original implementation acting as the de facto standard which other implementations aimed to follow. Since 2014, work has gone on to create a formal PHP specification.[11]

As of September 2019, over 60% of sites on the web using PHP are still on discontinued/"EOLed"[12] version 5.6 or older;[13] versions prior to 7.2 are no longer officially supported by The PHP Development Team,[14] but security support is provided by third parties, such as Debian.[15]

 

Contents

History[edit]

Early history[edit]

Rasmus Lerdorf, who wrote the original Common Gateway Interface (CGI) component, together with Andi Gutmans and Zeev Suraski, who rewrote the parser that formed PHP 3.

PHP development began in 1994 when Rasmus Lerdorf wrote several Common Gateway Interface (CGI) programs in C,[16][17][18] which he used to maintain his personal homepage. He extended them to work with web forms and to communicate with databases, and called this implementation "Personal Home Page/Forms Interpreter" or PHP/FI.

PHP/FI could be used to build simple, dynamic web applications. To accelerate bug reporting and improve the code, Lerdorf initially announced the release of PHP/FI as "Personal Home Page Tools (PHP Tools) version 1.0" on the Usenet discussion group comp.infosystems.www.authoring.cgi on June 8, 1995.[19][20] This release already had the basic functionality that PHP has today. This included Perl-like variables, form handling, and the ability to embed HTML. The syntax resembled that of Perl, but was simpler, more limited and less consistent.[6]

An example of the early PHP syntax:

<!--include /text/header.html-->

<!--getenv HTTP_USER_AGENT-->
<!--ifsubstr $exec_result Mozilla-->
  Hey, you are using Netscape!<p>
<!--endif-->

<!--sql database select * from table where user='$username'-->
<!--ifless $numentries 1-->
  Sorry, that record does not exist<p>
<!--endif exit-->
  Welcome <!--$user-->!<p>
  You have <!--$index:0--> credits left in your account.<p>

<!--include /text/footer.html-->

Early PHP was not intended to be a new programming language, and grew organically, with Lerdorf noting in retrospect: "I don't know how to stop it, there was never any intent to write a programming language [...] I have absolutely no idea how to write a programming language, I just kept adding the next logical step on the way."[21] A development team began to form and, after months of work and beta testing, officially released PHP/FI 2 in November 1997.

The fact that PHP was not originally designed, but instead was developed organically has led to inconsistent naming of functions and inconsistent ordering of their parameters.[22] In some cases, the function names were chosen to match the lower-level libraries which PHP was "wrapping",[23] while in some very early versions of PHP the length of the function names was used internally as a hash function, so names were chosen to improve the distribution of hash values.[24]

PHP 3 and 4[edit]

This is an example of custom PHP code for the WordPress content management system.

Zeev Suraski and Andi Gutmans rewrote the parser in 1997 and formed the base of PHP 3, changing the language's name to the recursive acronym PHP: Hypertext Preprocessor.[6][25] Afterwards, public testing of PHP 3 began, and the official launch came in June 1998. Suraski and Gutmans then started a new rewrite of PHP's core, producing the Zend Engine in 1999.[26] They also founded Zend Technologies in Ramat Gan, Israel.[6]

On May 22, 2000, PHP 4, powered by the Zend Engine 1.0, was released.[6] As of August 2008 this branch reached version 4.4.9. PHP 4 is no longer under development nor will any security updates be released.[27][28]

PHP 5[edit]

On July 14, 2004, PHP 5 was released, powered by the new Zend Engine II.[6] PHP 5 included new features such as improved support for object-oriented programming, the PHP Data Objects (PDO) extension (which defines a lightweight and consistent interface for accessing databases), and numerous performance enhancements.[29] In 2008, PHP 5 became the only stable version under development. Late static binding had been missing from PHP and was added in version 5.3.[30][31]

Many high-profile open-source projects ceased to support PHP 4 in new code as of February 5, 2008, because of the GoPHP5 initiative,[32] provided by a consortium of PHP developers promoting the transition from PHP 4 to PHP 5.[33][34]

Over time, PHP interpreters became available on most existing 32-bit and 64-bit operating systems, either by building them from the PHP source code, or by using pre-built binaries.[35] For PHP versions 5.3 and 5.4, the only available Microsoft Windows binary distributions were 32-bit IA-32 builds,[36][37] requiring Windows 32-bit compatibility mode while using Internet Information Services (IIS) on a 64-bit Windows platform. PHP version 5.5 made the 64-bit x86-64 builds available for Microsoft Windows.[38]

Official security support for PHP 5.6 ended on 31 December 2018,[39] but Debian 8.0 Jessie will extend support until June 2020.[15]

PHP 6 and Unicode[edit]

PHP received mixed reviews due to lacking native Unicode support at the core language level.[40][41] In 2005, a project headed by Andrei Zmievski was initiated to bring native Unicode support throughout PHP, by embedding the International Components for Unicode (ICU) library, and representing text strings as UTF-16 internally.[42] Since this would cause major changes both to the internals of the language and to user code, it was planned to release this as version 6.0 of the language, along with other major features then in development.[43]

However, a shortage of developers who understood the necessary changes, and performance problems arising from conversion to and from UTF-16, which is rarely used in a web context, led to delays in the project.[44] As a result, a PHP 5.3 release was created in 2009, with many non-Unicode features back-ported from PHP 6, notably namespaces. In March 2010, the project in its current form was officially abandoned, and a PHP 5.4 release was prepared containing most remaining non-Unicode features from PHP 6, such as traits and closure re-binding.[45] Initial hopes were that a new plan would be formed for Unicode integration, but as of 2014 none had been adopted.

PHP 7[edit]

During 2014 and 2015, a new major PHP version was developed, which was numbered PHP 7. The numbering of this version involved some debate.[46] While the PHP 6 Unicode experiment had never been released, several articles and book titles referenced the PHP 6 name, which might have caused confusion if a new release were to reuse the name.[47] After a vote, the name PHP 7 was chosen.[48]

The foundation of PHP 7 is a PHP branch that was originally dubbed PHP next generation (phpng). It was authored by Dmitry Stogov, Xinchen Hui and Nikita Popov,[49] and aimed to optimize PHP performance by refactoring the Zend Engine while retaining near-complete language compatibility.[50] As of 14 July 2014, WordPress-based benchmarks, which served as the main benchmark suite for the phpng project, showed an almost 100% increase in performance. Changes from phpng are also expected to make it easier to improve performance in the future, as more compact data structures and other changes are seen as better suited for a successful migration to a just-in-time (JIT) compiler.[51] Because of the significant changes, the reworked Zend Engine is called Zend Engine 3, succeeding Zend Engine 2 used in PHP 5.[52]

Because of major internal changes in phpng it must receive a new major version number of PHP, rather than a minor PHP 5 release, according to PHP's release process.[53] Major versions of PHP are allowed to break backward-compatibility of code and therefore PHP 7 presented an opportunity for other improvements beyond phpng that require backward-compatibility breaks. In particular, it involved the following changes:

  • Many fatal- or recoverable-level legacy PHP error mechanisms were replaced with modern object-oriented exceptions[54]
  • The syntax for variable dereferencing was reworked to be internally more consistent and complete, allowing the use of the operators ->[](),{}, and ::, with arbitrary meaningful left-side expressions[55]
  • Support for legacy PHP 4-style constructor methods was deprecated[56]
  • The behavior of the foreach statement was changed to be more predictable[57]
  • Constructors for the few classes built-in to PHP which returned null upon failure were changed to throw an exception instead, for consistency[58]
  • Several unmaintained or deprecated server application programming interfaces (SAPIs) and extensions were removed from the PHP core, most notably the legacy mysql extension[59]
  • The behavior of the list() operator was changed to remove support for strings[60]
  • Support was removed for legacy ASP-style delimiters <% and %> and <script language="php"> ... </script>[61]
  • An oversight allowing a switch statement to have multiple default clauses was fixed[62]
  • Support for hexadecimal number support in some implicit conversions from strings to number types was removed[63]
  • The left-shift and right-shift operators were changed to behave more consistently across platforms[64]
  • Conversions between integers and floating point numbers were tightened and implemented more consistently across platforms[64][65]

PHP 7 also included new language features. Most notably, it introduces return type declarations for functions[66] which complement the existing parameter type declarations, and support for the scalar types (integer, float, string, and boolean) in parameter and return type declarations.[67]

Release history[edit]

Version Release date Supported until[14] Notes
1.0 8 June 1995   Officially called "Personal Home Page Tools (PHP Tools)". This is the first use of the name "PHP".[6]
2.0 1 November 1997   Officially called "PHP/FI 2.0". This is the first release that could actually be characterised as PHP, being a standalone language with many features that have endured to the present day.
3.0 6 June 1998 20 October 2000[14] Development moves from one person to multiple developers. Zeev Suraski and Andi Gutmans rewrite the base for this version.[6]
4.0 22 May 2000 23 June 2001[14] Added more advanced two-stage parse/execute tag-parsing system called the Zend engine.[68]
4.1 10 December 2001 12 March 2002[14] Introduced "superglobals" ($_GET$_POST$_SESSION, etc.)[68]
4.2 22 April 2002 6 September 2002[14] Disabled register_globals by default. Data received over the network is not inserted directly into the global namespace anymore, closing possible security holes in applications.[68]
4.3 27 December 2002 31 March 2005[14] Introduced the command-line interface (CLI), to supplement the CGI.[68][69]
4.4 11 July 2005 7 August 2008[14] Fixed a memory corruption bug, which required breaking binary compatibility with extensions compiled against PHP version 4.3.x.[70]
5.0 13 July 2004 5 September 2005[14] Zend Engine II with a new object model.[71]
5.1 24 November 2005 24 August 2006[14] Performance improvements with introduction of compiler variables in re-engineered PHP Engine.[71] Added PHP Data Objects (PDO) as a consistent interface for accessing databases.[72]
5.2 2 November 2006 6 January 2011[14] Enabled the filter extension by default. Native JSON support.[71]
5.3 30 June 2009 14 August 2014[14] Namespace support; late static bindings, jump label (limited goto), closures, PHP archives (phar), garbage collection for circular references, improved Windows support, sqlite3, mysqlnd as a replacement for libmysql as underlying library for the extensions that work with MySQL, fileinfo as a replacement for mime_magic for better MIME support, the Internationalization extension, and deprecation of ereg extension.
5.4 1 March 2012 3 September 2015[14] Trait support, short array syntax support. Removed items: register_globalssafe_modeallow_call_time_pass_referencesession_register()session_unregister() and session_is_registered(). Built-in web server.[73] Several improvements to existing features, performance and reduced memory requirements.
5.5 20 June 2013 10 July 2016[74] Support for generatorsfinally blocks for exceptions handling, OpCache (based on Zend Optimizer+) bundled in official distribution.[75]
5.6 28 August 2014 31 December 2018[74] Constant scalar expressions, variadic functions, argument unpacking, new exponentiation operator, extensions of the use statement for functions and constants, new phpdbg debugger as a SAPI module, and other smaller improvements.[76]
6.x Not released N/A Abandoned version of PHP that planned to include native Unicode support.[77][78]
7.0 3 December 2015[79] 3 December 2018[53] Zend Engine 3 (performance improvements[51] and 64-bit integer support on Windows[80]), uniform variable syntax,[55] AST-based compilation process,[81] added Closure::call(),[82] bitwise shift consistency across platforms,[83] ?? (null coalesce) operator,[84] Unicode code point escape syntax,[85] return type declarations,[66] scalar type (integer, float, string and boolean) declarations,[67] <=> "spaceship" three-way comparison operator,[86] generator delegation,[87] anonymous classes,[88] simpler and more consistently available CSPRNG API,[89] replacement of many remaining internal PHP "errors" with the more modern exceptions,[54] and shorthand syntax for importing multiple items from a namespace.[90]
7.1 1 December 2016 1 December 2019[74] void return type,[91] class constant visibility modifiers[92]
7.2 30 November 2017 30 November 2020[74] Object parameter and return type hint,[93] Libsodium extension,[94] Abstract method overriding,[95] Parameter type widening[96]
7.3 6 December 2018[97] 6 December 2021 Flexible Heredoc and Nowdoc syntax,[98] support for reference assignment and array deconstruction with list(),[99] PCRE2 support,[100] hrtime() function[101]
7.4 28 November 2019[102] 28 November 2022 Typed Properties 2.0,[103] Preloading,[104] Null Coalescing Assignment Operator,[105] Improve openssl_random_pseudo_bytes,[106] Weak References,[107] FFI – Foreign Function Interface[108]

Always available hash extension,[109] Password Hash Registry,[110] Split multibyte string,[111] Reflection for references,[112] Unbundle ext/wddx,[113] New custom object serialization mechanism[114]

8.0 Q4 2020 or Q1 2021 Q4 2023 or Q1 2024 Just In Time compilation (JIT),[115] arrays starting with a negative index,[116] consistent type errors for internal functions,[117] fatal error for incompatible method signatures[118]

Legend:

Old version

Older version, still maintained

Latest version

Latest preview version

Future release

Beginning on June 28, 2011, the PHP Development Team implemented a timeline for the release of new versions of PHP.[53] Under this system, at least one release should occur every month. Once per year, a minor release should occur which may include new features. Every minor release should at least be supported for two years with security and bug fixes, followed by at least one year of only security fixes, for a total of a three-year release process for every minor release. No new features, unless small and self-contained, are to be introduced into a minor release during the three-year release process. Latest versions of PHP are PHP 7.2.26, PHP 7.3.13 and PHP 7.4.1 released on 18 Dec 2019.

Mascot[edit]

The elePHPant, PHP mascot

The mascot of the PHP project is the elePHPant, a blue elephant with the PHP logo on its side, designed by Vincent Pontier[119] in 1998.[120] "The (PHP) letters were forming the shape of an elephant if viewed in a sideways angle."[121] The elePHPant is sometimes differently colored when in plush toy form.

Many variations of this mascot have been made over the years. Only the elePHPants based on the original design by Vincent Pontier are considered official by the community.[122] These are collectible and some of them are extremely rare[citation needed]. Different variations are listed on A Field Guide to Elephpants.

Syntax[edit]

Main article: PHP syntax and semantics

The following "Hello, World!" program is written in PHP code embedded in an HTML document:

<!DOCTYPE html>
<html>
 <head>
  <title>PHP "Hello, World!" program</title>
 </head>
 <body>
  <?php echo '<p>Hello, World!</p>'; ?>
 </body>
</html>

However, as no requirement exists for PHP code to be embedded in HTML, the simplest version of Hello, World! may be written like this, with the closing tag omitted as preferred in files containing pure PHP code[123]

 <?='Hello, World!';

As well, there is no requirement that a PHP file contain PHP code at all – the interpreter will output data outside of PHP tags unchanged so a simple text file containing "Hello, World!" will give the same output.

The PHP interpreter only executes PHP code within its delimiters. Anything outside its delimiters is not processed by PHP, although non-PHP text is still subject to control structures described in PHP code. The most common delimiters are <?php to open and ?> to close PHP sections. The shortened form <? also exists. This short delimiter makes script files less portable, since support for them can be disabled in the local PHP configuration and it is therefore discouraged;[124][125] there is no recommendation against the echo short tag <?=.[126] Prior to PHP 5.4.0, this short syntax for echo() only works with the short_open_tag configuration setting enabled, while for PHP 5.4.0 and later it is always available.[127][128][124] The purpose of all these delimiters is to separate PHP code from non-PHP content, such as JavaScript code or HTML markup.[129]

The first form of delimiters, <?php and ?>, in XHTML and other XML documents, creates correctly formed XML processing instructions.[130] This means that the resulting mixture of PHP code and other markup in the server-side file is itself well-formed XML.

Variables are prefixed with a dollar symbol, and a type does not need to be specified in advance. PHP 5 introduced type hinting that allows functions to force their parameters to be objects of a specific class, arrays, interfaces or callback functions. However, before PHP 7.0, type hints could not be used with scalar types such as integer or string.[67]

Unlike function and class names, variable names are case sensitive. Both double-quoted ("") and heredoc strings provide the ability to interpolate a variable's value into the string.[131] PHP treats newlines as whitespace in the manner of a free-form language, and statements are terminated by a semicolon.[132] PHP has three types of comment syntax/* */ marks block and inline comments; // or # are used for one-line comments.[133] The echo statement is one of several facilities PHP provides to output text.

In terms of keywords and language syntax, PHP is similar to the C style syntax. if conditions, for and while loops, and function returns are similar in syntax to languages such as C, C++, C#, Java and Perl.

Data types[edit]

PHP stores integers in a platform-dependent range, either a 64-bit or 32-bit or 128-bit signed integer equivalent to the C-language long type. Unsigned integers are converted to signed values in certain situations; this behavior is different from other programming languages.[134] Integer variables can be assigned using decimal (positive and negative), octalhexadecimal, and binary notations.

Floating point numbers are also stored in a platform-specific range. They can be specified using floating point notation, or two forms of scientific notation.[135] PHP has a native Boolean type that is similar to the native Boolean types in Java and C++. Using the Boolean type conversion rules, non-zero values are interpreted as true and zero as false, as in Perl and C++.[135]

The null data type represents a variable that has no value; NULL is the only allowed value for this data type.[135] Old versions of the interpreter allowed multiple copies of this value to exist.

Variables of the "resource" type represent references to resources from external sources. These are typically created by functions from a particular extension, and can only be processed by functions from the same extension; examples include file, image, and database resources.[135]

Arrays can contain elements of any type that PHP can handle, including resources, objects, and even other arrays. Order is preserved in lists of values and in hashes with both keys and values, and the two can be intermingled.[135] PHP also supports strings, which can be used with single quotes, double quotes, nowdoc or heredoc syntax.[136]

The Standard PHP Library (SPL) attempts to solve standard problems and implements efficient data access interfaces and classes.[137]

Functions[edit]

PHP defines a large array of functions in the core language and many are also available in various extensions; these functions are well documented in the online PHP documentation.[138] However, the built-in library has a wide variety of naming conventions and associated inconsistencies, as described under history above.

Custom functions may be defined by the developer:

function myAge(int $birthYear): string
{
    // calculate the age by subtracting the birth year from the current year.
    $yearsOld = date('Y') - $birthYear;

    // return the age in a descriptive string.
    return $yearsOld . ' year' . ($yearsOld != 1 ? 's':'');
}

echo 'I am currently ' . myAge(1995) . ' old.';

In 2020, the output of the above sample program is 'I am currently 25 years old.'

In lieu of function pointers, functions in PHP can be referenced by a string containing their name. In this manner, normal PHP functions can be used, for example, as callbacks or within function tables.[139] User-defined functions may be created at any time without being prototyped.[138][139] Functions may be defined inside code blocks, permitting a run-time decision as to whether or not a function should be defined. There is a function_exists function that determines whether a function with a given name has already been defined. Function calls must use parentheses, with the exception of zero-argument class constructor functions called with the PHP operator new, in which case parentheses are optional.

Until PHP 5.3, support for anonymous functions and closures did not exist in PHP. While create_function() has existed since PHP 4.0.1, it is merely a thin wrapper around eval() that allows normal PHP functions to be created during program execution.[140] PHP 5.3 added syntax to define an anonymous function or "closure"[141] which can capture variables from the surrounding scope:

function getAdder($x)
{
    return function($y) use ($x) {
        return $x + $y;
    };
}

$adder = getAdder(8);
echo $adder(2); // prints "10"

In the example above, getAdder() function creates a closure using passed argument $x (the keyword use imports a variable from the lexical context), which takes an additional argument $y, and returns the created closure to the caller. Such a function is a first-class object, meaning that it can be stored in a variable, passed as a parameter to other functions, etc.[142]

Unusually for a dynamically typed language, PHP supports type declarations on function parameters, which are enforced at runtime. This has been supported for classes and interfaces since PHP 5.0, for arrays since PHP 5.1, for "callables" since PHP 5.4, and scalar (integer, float, string and boolean) types since PHP 7.0.[67] PHP 7.0 also has type declarations for function return types, expressed by placing the type name after the list of parameters, preceded by a colon.[66] For example, the getAdder function from the earlier example could be annotated with types like so in PHP 7:

function getAdder(int $x): Closure
{
    return function(int $y) use ($x): int
    {
        return $x + $y;
    };
}

$adder = getAdder(8);
echo $adder(2); // prints "10"
echo $adder(null); // throws an exception because an incorrect type was passed
$adder = getAdder([]); // would also throw an exception

By default, scalar type declarations follow weak typing principles. So, for example, if a parameter's type is int, PHP would allow not only integers, but also convertible numeric strings, floats or booleans to be passed to that function, and would convert them.[67] However, PHP 7 has a "strict typing" mode which, when used, disallows such conversions for function calls and returns within a file.[67]

PHP Objects[edit]

Basic object-oriented programming functionality was added in PHP 3 and improved in PHP 4.[6] This allowed for PHP to gain further abstraction, making creative tasks easier for programmers using the language. Object handling was completely rewritten for PHP 5, expanding the feature set and enhancing performance.[143] In previous versions of PHP, objects were handled like value types.[143] The drawback of this method was that code had to make heavy use of PHP's "reference" variables if it wanted to modify an object it was passed rather than creating a copy of it. In the new approach, objects are referenced by handle, and not by value.

PHP 5 introduced private and protected member variables and methods, along with abstract classesfinal classesabstract methods, and final methods. It also introduced a standard way of declaring constructors and destructors, similar to that of other object-oriented languages such as C++, and a standard exception handling model. Furthermore, PHP 5 added interfaces and allowed for multiple interfaces to be implemented. There are special interfaces that allow objects to interact with the runtime system. Objects implementing ArrayAccess can be used with array syntax and objects implementing Iterator or IteratorAggregate can be used with the foreach language construct. There is no virtual table feature in the engine, so static variables are bound with a name instead of a reference at compile time.[144]

If the developer creates a copy of an object using the reserved word clone, the Zend engine will check whether a __clone() method has been defined. If not, it will call a default __clone() which will copy the object's properties. If a __clone() method is defined, then it will be responsible for setting the necessary properties in the created object. For convenience, the engine will supply a function that imports the properties of the source object, so the programmer can start with a by-value replica of the source object and only override properties that need to be changed.[145]

The following is a basic example of object-oriented programming in PHP:

 1 <?php
 2 
 3 abstract class User
 4 {
 5     public string $name;
 6 
 7     public function __construct(string $name)
 8     {
 9         $this->name = $name;
10     }
11 
12     public function greet(): string
13     {
14         return "Hello, my name is " . $this->name;
15     }
16 
17     abstract public function job(): string;
18 }
19 
20 class Student extends User
21 {
22     public string $course;
23 
24     public function __construct(string $name, string $course)
25     {
26         $this->course = $course;
27         parent::__construct($name);
28     }
29 
30     public function job(): string
31     {
32         return "I learn " . $this->course;
33     }
34 }
35 
36 class Teacher extends User
37 {
38     public array $teachingCourses;
39 
40     public function __construct(string $name, string...$teachingCourses)
41     {
42         $this->teachingCourses = $teachingCourses;
43         parent::__construct($name);
44     }
45 
46     public function job(): string
47     {
48         return "I teach " . implode(", ", $this->teachingCourses);
49     }
50 }
51 
52 $students = [
53     new Student("Alice", "Computer Science"),
54     new Student("Bob", "Computer Science"),
55     new Student("Charlie", "Business Studies"),
56 ];
57 $teachers = [
58     new Teacher("Dan", "Computer Science", "Information Security"),
59     new Teacher("Erin", "Computer Science", "3D Graphics Programming"),
60     new Teacher("Frankie", "Online Marketing", "Business Studies", "E-commerce"),
61 ];
62 
63 echo "Students: \n";
64 foreach ($students as $student) {
65     echo $student->greet() . ", " . $student->job() . "\n";
66 }
67 
68 echo "Teachers: \n";
69 foreach ($teachers as $teacher) {
70     echo $teacher->greet() . ", " . $teacher->job() . "\n";
71 }
72 
73 // Output of program:
74 // Students:
75 // Hello, my name is Alice, I learn Computer Science
76 // Hello, my name is Bob, I learn Computer Science
77 // Hello, my name is Charlie, I learn Business Studies
78 // Teachers:
79 // Hello, my name is Dan, I teach Computer Science, Information Security
80 // Hello, my name is Erin, I teach Computer Science, 3D Graphics Programming
81 // Hello, my name is Frankie, I teach Online Marketing, Business Studies, E-commerce

The visibility of PHP properties and methods is defined using the keywords publicprivate, and protected. The default is public, if only var is used; var is a synonym for public. Items declared public can be accessed everywhere. protected limits access to inherited classes (

Comments
Calvins Ongele says...

w


Add Comment

Note: We sanitize our comments to keep them clean!

Share this Page