|
|
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.
|
The function names __construct,
__destruct (see Constructors and Destructors),
__call, __get, __set,
__isset, __unset (see Overloading), __sleep, __wakeup,
__toString, __set_state, __clone and __autoload are magical in PHP
classes. You cannot have functions with these names in any of
your classes unless you want the magic functionality associated
with them.
| Uwaga! |
|
PHP reserves all function names starting with __ as
magical. It is recommended that you do not use function
names with __ in PHP unless you want some documented
magic functionality.
|
serialize() checks if your class has a
function with the magic name __sleep. If so, that function is executed
prior to any serialization. It can clean up the object and is
supposed to return an array with the names of all variables
of that object that should be serialized.
The intended use of __sleep is
to close any database connections that the object may have,
commit pending data or perform similar cleanup tasks. Also,
the function is useful if you have very large objects which
do not need to be saved completely.
Conversely, unserialize() checks for the presence of a
function with the magic name __wakeup. If present, this function can
reconstruct any resources that the object may have.
The intended use of __wakeup is
to reestablish any database connections that may have been
lost during serialization and perform other reinitialization
tasks.
Przykład 19-26. Sleep and wakeup
<?php class Connection {
protected $link;
private $server, $username, $password, $db;
public function __construct($server, $username, $password, $db)
{
$this->server = $server;
$this->username = $username;
$this->password = $password;
$this->db = $db;
$this->connect();
}
private function connect()
{
$this->link = mysql_connect($this->server, $this->username, $this->password);
mysql_select_db($this->db, $this->link);
}
public function __sleep()
{
mysql_close($this->link);
}
public function __wakeup()
{
$this->connect();
}
} ?> |
|
The __toString method allows a
class to decide how it will react when it is converted to a
string.
Przykład 19-27. Simple example
<?php // Declare a simple class
class TestClass {
public $foo;
public function __construct($foo) {
$this->foo = $foo;
}
public function __toString() {
return $this->foo;
}
}
$class = new TestClass('Hello');
echo $class; ?> |
Powyższy przykład wyświetli:
|
It is worth noting that the __toString method will only be called when it
is directly combined with echo() or
print().
Przykład 19-28. Cases where __toString is called
<?php // __toString called
echo $class;
// __toString called (still a normal parameter for echo)
echo 'text', $class;
// __toString not called (concatenation operator used first)
echo 'text' . $class;
// __toString not called (cast to string first)
echo (string) $class;
// __toString not called (cast to string first)
echo "text $class"; ?> |
|
This static method
is called for classes exported by var_export() since PHP 5.1.0.
The only parameter of this method is an array containing
exported properties in the form array('property' => value, ...).
|