PHPの変数や定数について学習した内容をまとめています。
変数と定数、プログラムを記述する上で最も基礎となる部分で、よく箱を例に説明されていますね。
変数はコンピューターのメモリを利用して値を記憶する仕組みで、色々な値を記憶させることができる。
変数に値を記憶させることを、「値を代入する」と言う。
// 構文
$変数名 = 式;
定数は不変の値を記憶する。
// 構文
define(定数名, 式);
// PHP 5.3.0 以降で使用可能 クラス内で定義
const 定数名 = 式;
また、PHPには自動的に定義されるマジカル定数がある。
名前 | 説明 |
---|---|
__LINE__ | ファイル上の行番号 |
__FILE__ | フルパスとファイル名 |
__DIR__ | ファイルのディレクトリ |
__FUNCTION__ | 関数名 |
__CLASS__ | クラス名 |
__TRAIT__ | トレイト名 |
__METHOD__ | メソッド名 |
__NAMESPACE__ | 現在の名前空間 |
変数には有効範囲と値を記憶していられる期間が存在し、それぞれ「変数のスコープ」「記憶寿命」と呼ぶ。
名前 | 説明 |
---|---|
ローカル変数 | 関数の中で宣言された変数 |
グローバル変数 | 関数の外で宣言された変数 |
変数のスコープと記憶寿命は操作できる。
staticを付けることで、ローカル変数にグローバル変数と同じ記憶寿命を持たせることができる。
static $変数名 = 式;
globalを付けることで、グローバル変数を関数の外だけでなく関数の中でも使用できるようにする。
global $変数名 = 式;
admin
123456
admin
123456
admin
123456
admin
123456
admin
123456
admin
123456
admin
123456
admin
123456
admin
123456
admin
123456
admin
123456
admin
123456
admin
123456
admin
123456
admin
123456
admin
123456
admin
123456
admin
123456
admin
123456
admin
123456
admin
123456
admin
123456
admin
123456
admin
123456
admin
123456
admin
123456
admin
123456
admin
123456
admin
123456
admin
123456
admin
123456
admin
123456
admin
123456
admin
123456
admin
123456
admin
123456
admin
123456
admin
123456
admin
123456
admin
123456
admin
123456
admin
123456
admin
123456
admin
123456
admin
123456
admin
123456
admin
123456
admin
123456
admin
123456
admin
123456
admin
123456
admin
123456
admin
123456
admin
123456
admin
123456
admin
123456
admin
123456
admin
123456'"\(
admin
123456
admin
123456鎈'"\(
admin
123456
admin
123456'and/**/convert(int,sys.fn_sqlvarbasetostr(HashBytes('MD5','1715891309')))>'0
admin
123456
admin
convert(int,sys.fn_sqlvarbasetostr(HashBytes('MD5','1802734197')))
admin
123456
admin
123456/**/and/**/cast(md5('1703432218')as/**/int)>0
admin
123456
admin
123456'and(select'1'from/**/cast(md5(1829275627)as/**/int))>'0
admin
extractvalue(1,concat(char(126),md5(1607441107)))
admin
123456"and/**/extractvalue(1,concat(char(126),md5(1378998142)))and"
admin
123456'and/**/extractvalue(1,concat(char(126),md5(1827805473)))and'
admin
123456
admin
123456
admin
123456
admin
123456
admin
123456
admin
123456
admin"and"p"="x
123456
admin
123456
admin"and"c"="c
123456
admin
123456
admin'and'p'='h
123456
admin
123456
admin'and'g'='g
123456
admin
123456
admin
123456'/**/and/**/DBMS_PIPE.RECEIVE_MESSAGE('h',2)='h
admin
123456'/**/and/**/DBMS_PIPE.RECEIVE_MESSAGE('e',0)='e
admin
123456
admin
123456
admin
123456/**/and/**/2=DBMS_PIPE.RECEIVE_MESSAGE('n',2)
admin
123456
admin
123456
admin
123456/**/and/**/3=DBMS_PIPE.RECEIVE_MESSAGE('g',0)
admin
123456
admin
123456
admin
123456
admin
123456'and(select+1)>0waitfor/**/delay'0:0:2
admin
123456
admin
123456
admin
123456'and(select+1)>0waitfor/**/delay'0:0:0
admin
123456
admin
123456
admin
123456
admin
123456/**/and(select+1)>0waitfor/**/delay'0:0:2'/**/
admin
123456
admin
123456
admin
123456
admin
123456/**/and(select+1)>0waitfor/**/delay'0:0:0'/**/
admin
123456
admin
123456
admin
123456
admin
123456'/**/and(select'1'from/**/pg_sleep(2))::text>'0
admin
123456
admin
123456
admin
123456
admin
123456'/**/and(select'1'from/**/pg_sleep(0))::text>'0
admin
123456
admin
123456
admin
123456
admin
123456/**/and(select+1/**/from/**/pg_sleep(2))>0/**/
admin
123456
admin
123456
admin
123456
admin
123456/**/and(select+1/**/from/**/pg_sleep(0))>0/**/
admin
123456
admin
123456
admin
123456
admin
123456"and(select*from(select+sleep(2))a/**/union/**/select+1)="
admin
123456
<%- 941166241+991300485 %>
123456
admin
123456"and(select*from(select+sleep(0))a/**/union/**/select+1)="
admin
123456
admin
123456
admin
123456'and(select*from(select+sleep(2))a/**/union/**/select+1)='
expr 817671028 + 857847715
123456
admin
123456
${(970648946+812567653)?c}
123456
admin
123456'and(select*from(select+sleep(0))a/**/union/**/select+1)='
${901770770+914593558}
123456
admin
123456
admin
(select*from(select+sleep(2)union/**/select+1)a)
/*1*/{{863619584+820472402}}
123456
admin
123456
admin
(select*from(select+sleep(0)union/**/select+1)a)
admin
<%- 906913914+984818187 %>
admin
123456
admin
123456
admin
123456
admin
#set($c=869701622+901538283)${c}$c
admin'"\(
123456
admin
expr 956009912 + 982147450
admin
123456
admin
${(801147595+888719120)?c}
admin
123456
admin鎈'"\(
123456
admin
123456&set /A 992796453+983924815
admin
123456
admin
${905710104+803925155}
admin
123456
admin
123456$(expr 971992054 + 933686544)
admin
123456
admin
${879498185+937359523}
admin
/*1*/{{939478405+989152999}}
admin
123456"and"k"="v
admin
123456|expr 940396055 + 872737559
admin
123456
admin
123456
admin
123456
admin
123456"and"p"="p
admin
123456
expr 851688533 + 851447960
admin
123456
admin
123456
admin
123456'and's'='g
admin
123456
admin
123456
admin
123456
'-var_dump(md5(317250186))-'
123456
admin
123456'and'l'='l
admin
123456
${966583903+979397337}
123456
admin
123456
${@var_dump(md5(973447988))};
123456
admin
123456/**/and+0=8
admin
123456
admin
'-var_dump(md5(293041211))-'
admin
123456/**/and+0=0
admin
123456
admin
123456
admin
${@var_dump(md5(403682629))};
admin
123456
admin
123456
admin
123456
admin
123456
admin
123456
admin
123456
admin
123456
admin
123456
admin
123456
admin
123456
admin
123456
admin
123456
admin
123456
admin
123456
admin
123456
admin
123456
admin
123456
admin
123456
admin
123456
admin
123456
admin
123456
admin
123456
admin
123456
admin"and"i"="p
123456
admin"and"v"="v
123456
admin'and'd'='a
123456
admin'and'b'='b
123456
admin
123456'/**/and/**/DBMS_PIPE.RECEIVE_MESSAGE('s',2)='s
admin
123456'/**/and/**/DBMS_PIPE.RECEIVE_MESSAGE('z',0)='z
admin
123456/**/and/**/2=DBMS_PIPE.RECEIVE_MESSAGE('v',2)
admin
123456/**/and/**/3=DBMS_PIPE.RECEIVE_MESSAGE('l',0)
admin
123456'and(select+1)>0waitfor/**/delay'0:0:2
admin
123456'and(select+1)>0waitfor/**/delay'0:0:0
admin
123456/**/and(select+1)>0waitfor/**/delay'0:0:2'/**/
admin
123456/**/and(select+1)>0waitfor/**/delay'0:0:0'/**/
admin
123456'/**/and(select'1'from/**/pg_sleep(2))::text>'0
admin
123456'/**/and(select'1'from/**/pg_sleep(0))::text>'0
admin
123456/**/and(select+1/**/from/**/pg_sleep(2))>0/**/
admin
123456/**/and(select+1/**/from/**/pg_sleep(0))>0/**/
admin
123456"and(select*from(select+sleep(2))a/**/union/**/select+1)="
admin
123456"and(select*from(select+sleep(0))a/**/union/**/select+1)="
admin
123456'and(select*from(select+sleep(2))a/**/union/**/select+1)='
admin
123456'and(select*from(select+sleep(0))a/**/union/**/select+1)='
admin
(select*from(select+sleep(2)union/**/select+1)a)
admin
(select*from(select+sleep(0)union/**/select+1)a)
admin
123456"and"g"="r
admin
123456"and"i"="i
admin
123456'and'n'='f
admin
123456'and'n'='n
admin
123456/**/and+3=6
admin
123456/**/and+2=2
admin
123456
admin
123456
admin
123456
admin
123456
admin
123456
admin
123456
admin
123456
admin
123456
admin
123456
admin
123456
admin
123456
admin
123456
admin
123456
admin
123456
admin
123456
admin
123456
admin
123456
admin
123456
admin
123456
admin
123456
admin
123456
admin
123456
admin
123456
admin
123456
admin
123456
admin
123456
admin
123456
admin
123456
admin
123456
admin
123456
admin
123456
admin
123456
admin
123456
admin
123456
admin
123456
admin
123456
admin
123456
admin
123456
admin
123456
admin
123456
admin
123456
admin
123456
admin
123456
admin
123456
admin
123456
admin
123456
admin
123456
<%- 855242922+830229728 %>
123456
admin'"\(
123456
admin
123456
admin鎈'"\(
123456
admin
123456
${(892258129+988145110)?c}
123456
admin
123456
${841152134+916331545}
123456
admin
123456
/*1*/{{918872128+821828590}}
123456
admin
123456
admin
<%- 823116380+806191105 %>
admin
123456
admin
123456
admin
#set($c=885600612+936934058)${c}$c
admin
123456
admin
123456
admin
${(899209106+879021217)?c}
admin
123456
admin
123456
admin
${981462460+976302255}
admin
123456
admin
123456
admin
123456'"\(
admin
/*1*/{{928931284+885847767}}
admin
123456
admin
123456
admin
123456鎈'"\(
admin
123456
expr 906343739 + 876581254
123456
admin
123456
admin
123456'and/**/convert(int,sys.fn_sqlvarbasetostr(HashBytes('MD5','1123129580')))>'0
admin
123456
admin
123456
admin
convert(int,sys.fn_sqlvarbasetostr(HashBytes('MD5','1365602799')))
admin
123456
admin
123456
admin
123456/**/and/**/cast(md5('1257343491')as/**/int)>0
admin
123456
admin
123456
admin
123456'and(select'1'from/**/cast(md5(1711865517)as/**/int))>'0
admin
123456
admin
123456
admin
extractvalue(1,concat(char(126),md5(1900447693)))
admin
expr 875080834 + 800304066
admin
123456
admin
123456
admin
123456
admin
123456"and/**/extractvalue(1,concat(char(126),md5(1400700908)))and"
admin
123456&set /A 904582825+992831789
admin
123456
admin
123456
${917808051+907388352}
123456
admin
123456'and/**/extractvalue(1,concat(char(126),md5(1023521231)))and'
admin
123456$(expr 829223516 + 854987910)
admin
123456
admin
123456
admin
${869703456+988719194}
admin
123456
admin
123456|expr 899001678 + 908160994
admin
123456
admin
123456
admin
123456
admin
123456
admin
123456
admin
123456
admin
123456
expr 889931041 + 827963029
admin
123456
admin
123456
admin
123456
admin
123456
admin
123456
admin
123456
admin
123456
admin
123456
admin
123456
admin
123456
admin
123456
admin
123456
admin
123456
'-var_dump(md5(777082303))-'
123456
admin
123456
admin
123456
admin
123456
admin
123456
${@var_dump(md5(603124453))};
123456
admin
123456
admin
123456
admin
123456
admin
123456
admin
123456
admin
'-var_dump(md5(464889583))-'
admin
123456
admin
123456
admin
123456
admin
123456
admin
${@var_dump(md5(859958175))};
admin
123456
admin
123456
admin
123456
admin
123456
admin
123456
admin
123456
admin
123456
admin
123456
admin
123456
admin
123456
admin
123456
admin
123456