This is my first php program!



Download 6,9 Mb.
Pdf ko'rish
bet26/69
Sana26.02.2022
Hajmi6,9 Mb.
#471647
1   ...   22   23   24   25   26   27   28   29   ...   69
Bog'liq
PHP

Variables
|
33
update_counter( );
update_counter( );
echo "Global counter is $counter\n";
Static counter is now 1
Static counter is now 2
Global counter is 10
Function parameters
As we’ll discuss in more detail in Chapter 3, a function definition can have named
parameters:
function greet ($name) {
echo "Hello, $name\n";
}
greet("Janet");
Hello, Janet
Function parameters are local, meaning that they are available only inside their func-
tions. In this case,
$name
is inaccessible from outside
greet( )
.
Garbage Collection
PHP uses reference counting and copy-on-write to manage memory. Copy-on-write
ensures that memory isn’t wasted when you copy values between variables, and ref-
erence counting ensures that memory is returned to the operating system when it is
no longer needed.
To understand memory management in PHP, you must first understand the idea of a
symbol table
. There are two parts to a variable—its name (e.g.,
$name
), and its value
(e.g.,
"Fred"
). A symbol table is an array that maps variable names to the positions of
their values in memory.
When you copy a value from one variable to another, PHP doesn’t get more memory
for a copy of the value. Instead, it updates the symbol table to say “both of these
variables are names for the same chunk of memory.” So the following code doesn’t
actually create a new array:
$worker = array("Fred", 35, "Wilma");
$other = $worker; // array isn't copied
If you then modify either copy, PHP allocates the memory and makes the copy:
$worker[1] = 36; // array is copied, value changed
By delaying the allocation and copying, PHP saves time and memory in a lot of situa-
tions. This is copy-on-write.
Each value pointed to by a symbol table has a
reference count
, a number that repre-
sents the number of ways there are to get to that piece of memory. After the initial
assignment of the array to
$worker
and
$worker
to
$other
, the array pointed to by the
,ch02.15294 Page 33 Wednesday, March 13, 2002 11:42 AM


This is the Title of the Book, eMatter Edition
Copyright © 2002 O’Reilly & Associates, Inc. All rights reserved.

Download 6,9 Mb.

Do'stlaringiz bilan baham:
1   ...   22   23   24   25   26   27   28   29   ...   69




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©hozir.org 2024
ma'muriyatiga murojaat qiling

kiriting | ro'yxatdan o'tish
    Bosh sahifa
юртда тантана
Боғда битган
Бугун юртда
Эшитганлар жилманглар
Эшитмадим деманглар
битган бодомлар
Yangiariq tumani
qitish marakazi
Raqamli texnologiyalar
ilishida muhokamadan
tasdiqqa tavsiya
tavsiya etilgan
iqtisodiyot kafedrasi
steiermarkischen landesregierung
asarlaringizni yuboring
o'zingizning asarlaringizni
Iltimos faqat
faqat o'zingizning
steierm rkischen
landesregierung fachabteilung
rkischen landesregierung
hamshira loyihasi
loyihasi mavsum
faolyatining oqibatlari
asosiy adabiyotlar
fakulteti ahborot
ahborot havfsizligi
havfsizligi kafedrasi
fanidan bo’yicha
fakulteti iqtisodiyot
boshqaruv fakulteti
chiqarishda boshqaruv
ishlab chiqarishda
iqtisodiyot fakultet
multiservis tarmoqlari
fanidan asosiy
Uzbek fanidan
mavzulari potok
asosidagi multiservis
'aliyyil a'ziym
billahil 'aliyyil
illaa billahil
quvvata illaa
falah' deganida
Kompyuter savodxonligi
bo’yicha mustaqil
'alal falah'
Hayya 'alal
'alas soloh
Hayya 'alas
mavsum boyicha


yuklab olish