PHP
An Introduction for Programmers |
Prof. David Bernstein
|
Computer Science Department |
bernstdh@jmu.edu |
;
(except for the last statement)
{
and a }
;
#
and the end of the line
is a comment//
and the end of the line
is a comment/*
and a */
is a commentlong
type of the C compiler)double
type of the C compiler).
operator\
is the escape character and can be used to
represent special characters (e.g., \n
represents
the newline character) and Unicode characters
(e.g., \u00e9
is é)false
, 0
, 0.0
,
""
, an array with 0 elements, and
NULL
all evaluate to false
true
$
followed by an identifierNULL
$$
(e.g., $name = "price"; $$name = 5;
will
assign the value 5
to the
variable named price
)+
)-
)*
)/
)/
)%
)++
) and Decrement (--
)-
)>
<
>=
<=
==
===
!=
!==
&&
, and
||
, or
!
xor
if
Statementwhile
Loopsdo-while
Loopsfor
Loopsf
):
isset()
; default values
(i.e., including an assignment) in the formal parameter list;
and/or func_num_args()
and func_get_arg()
global
in that functionstatic
modifier in the
initializationdefine()
function[]
Operator:
count()
and sizeof()
Functions:
foreach
Loops[]
operator more than once
To pass a parameter by reference, include an &
before the variable name in the formal parameter list.
To pass a parameter by value, omit the &
.
To return by reference, include an &
before the
variable name in the formal parameter list and use
the =&
operator to assign the result.
To return by value, omit the &
and use the =
operator to assign the result.
this
:
Membership Operator
:
->
public
, protected
,
or private
) and a variable initialization
and method consists of a visibility and
a function declarationnew
Operator:
static
modifier::
operator and internally using
self
and the ::
operator
const
modifier (not the
define()
function)::
operator and internally using the
identifierarray
)
before the formal parameterNULL
)parent
and the ::
operatorself
and the
::
operator (rather than $this
and the ->
operator)abstract
modifier in the declaration
of the class or methodclass
replaced by interface
implements
class
replaced by trait
include
and require
Statements:
include
generates a warning and
require
generates a fatal error if the file
is not foundinclude_once
and require_once
Statements:
namespace
statementuse
statementfile_exists()
fopen()
and fclose()
fread()
and fwrite()
fscanf()
and fprintf()