PHP/CodeIgniter3
php @, &, :: 의미
September Choe
2020. 1. 15. 11:06
728x90
1. @ (Error control opertator)
존재하지 않는 butterfly.php를 include하려고 하면 'Warning: include(butterfly.php): failed to open stream: No such file or directory in', 'include(): Failed opening 'butterfly.php' for inclusion' 오류가 발생한다.
<?php
include("butterfly.php");
?>
하지만 include() 앞에 @를 붙이면 그런 오류메시지가 출력되지 않는다.
<?php
@include("butterfly.php");
?>
2. &
C의 포인터 같은 것. $b는 $a의 바로가기 같은 것이라고 생각하면 된다.
$a에 직접 +1을 하지 않아도, $b + 1의 결과로 $a는 2를 갖게 된다.
<?php
$a = 1;
$b = &$a;
$b = $b + 1;
echo "a값: " . $a;
echo "b값: " . $b;
?>
3. ::
class 속 const, static 변수에 접근할 수 있는 연산자.
$변수명:: 이나 $class명:: 의 형태로 사용할 수 있다.
<?php
class MyClass {
const PRINCIPAL = 'Kim';
static $students = "30명";
static $boy = "15명";
static $girl = "15명";
public function notice(){
echo "교장은 " . self::PRINCIPAL . "이다.";
}
public function event(){
echo "3월 10일은 운동회";
}
}
$classname = 'Myclass';
echo $classname::$students . "<br>";
echo $classname::notice() . "<br>";
echo Myclass::$students . "<br>";
echo Myclass::event() . "<br>";
?>
728x90
반응형