|
|
PHP (angielski akronim rekurencyjny, którego rozwinięcie to PHP Hypertext Preprocessor), pierwotnie nazwany Personal
Home Page - skryptowy język programowania, służący przede wszystkim do tworzenia dynamicznych stron WWW i wykonywany w
tym przypadku po stronie serwera, z możliwością zagnieżdżania w HTML (bądź XHTML). PHP jest podobny w założeniach do
dużo starszego mechanizmu SSI (Server Side Includes), jednak jest w stosunku do SSI nieporównanie bardziej rozbudowany.
Udostępniany jest na zasadach licencji open-source. Jego składnia bazuje na językach C, Java i Perl.
SQL (ang. Structured Query Language) to strukturalny język zapytań używany do tworzenia, modyfikowania baz danych oraz
do umieszczania i pobierania danych z baz danych.
Język SQL jest językiem deklaratywnym. Decyzję o sposobie przechowywania i pobrania danych pozostawia się systemowi
zarządzania bazą danych DBMS.
Jest to język programowania opracowany w latach siedemdziesiątych w firmie IBM. Stał się on standardem w komunikacji z
serwerami relacyjnych baz danych. Wiele współczesnych systemów relacyjnych baz danych używa do komunikacji z
użytkownikiem SQL, dlatego mówi się, że korzystanie z relacyjnych baz danych, to korzystanie z SQL-a.
Apache jest otwartym serwerem HTTP dostępnym dla wielu systemów operacyjnych (m.in. UNIX, GNU/Linux, BSD,
Microsoft Windows). Po angielsku słowo Apache wymawia się epaczi, co brzmi tak samo jak a patchy (server), co było
określeniem tego serwera we wczesnym stadium jego rozwoju w 1995 roku, kiedy był on głównie zbiorem poprawek (patch)
nałożonych na serwer HTTP o nazwie NCSA.
Apache jest najszerzej stosowanym serwerem HTTP w Internecie. W maju 2003 jego udział wśród serwerów wynosił 62%. W
połączeniu z interpreterem języka skryptowego PHP i bazą danych MySQL, Apache stanowi jedno z najczęściej spotykanych
środowisk w firmach oferujących miejsce na serwerach sieciowych.
|
Every class definition begins with the keyword class,
followed by a class name, which can be any name that isn't a
reserved word in PHP. Followed by
a pair of curly braces, which contains the definition of the
classes members and methods. A pseudo-variable, $this is available when a method is called
from within an object context. $this is a reference to the calling object
(usually the object to which the method belongs, but can be
another object, if the method is called statically from the context
of a secondary object). This is illustrated in the following
examples:
Przykład 19-1. $this
variable in object-oriented language
<?php class A
{
function foo()
{
if (isset($this)) {
echo '$this is defined (';
echo get_class($this);
echo ")\n";
} else {
echo "\$this is not defined.\n";
}
}
}
class B {
function bar()
{
A::foo();
}
}
$a = new A(); $a->foo(); A::foo(); $b = new B(); $b->bar(); B::bar(); ?> |
Powyższy przykład wyświetli:
$this is defined (a)
$this is not defined.
$this is defined (b)
$this is not defined.
|
|
Przykład 19-2. Simple Class definition
<?php class SimpleClass
{
// member declaration
public $var = 'a default value';
// method declaration
public function displayVar() {
echo $this->var;
}
} ?> |
|
Notatka: There are some nice functions to
handle classes and objects. You might want to take a look
at the Class/Object
Functions.
To create an instance of an object, a new object must be
created and assigned to a variable. An object will always be
assigned when creating a new object unless the object has a
constructor defined
that throws an exception on error.
Przykład 19-3. Creating an instance
<?php
$instance = new SimpleClass(); ?> |
|
When assigning an already created instance of an object to
a new variable, the new variable will access the same
instance as the object that was assigned. This behaviour is
the same when passing instances to a function. A new instance
of an already created object can be made by cloning it.
Przykład 19-4. Object Assignment
<?php
$assigned = $instance; $reference =& $instance;
$instance->var = '$assigned will have this value';
$instance = null; // $instance and $reference become null
var_dump($instance); var_dump($reference); var_dump($assigned); ?> |
Powyższy przykład wyświetli:
NULL
NULL
object(SimpleClass)#1 (1) {
["var"]=>
string(30) "$assigned will have this value"
}
|
|
A class can inherit methods and members of another class
by using the extends keyword in the declaration. It is not
possible to extend multiple classes, a class can only inherit
one base class.
The inherited methods and members can be overridden,
unless the parent class has defined a method as final, by redeclaring them
within the same name defined in the parent class. It is
possible to access the overrided method or members by
referencing them with parent::
Przykład 19-5. Simple Class
Inherintance
<?php class ExtendClass extends SimpleClass
{
// Redefine the parent method
function displayVar()
{
echo "Extending class\n";
parent::displayVar();
}
}
$extended = new ExtendClass(); $extended->displayVar(); ?> |
Powyższy przykład wyświetli:
Extending class
a default value
|
|
|