Root292 PHP Fatal error: Cannot redeclare function() (previously declared in ~) PHP Fatal error: Cannot redeclare function() (previously declared in ~) 주로 상단에 include한 파일중에 이미 선언된 function 이름과 같은 function을 또 선언했을때 나타나는 오류. function_exists()로 선언하고자 하는 function 이름이 이미 선언되어 있는지 체크 필요. 예시) // Bad; @include_once '/data/functions.php'; function test_function(){ } // GOOD! @include_once '/data/functions.php'; if(function_exists('test_function') == false){ function test_function(){.. Server Language/PHP 2020. 3. 10. PHP Warning: sizeof(): Parameter must be an array or an object that implements Countable in PHP Warning: sizeof(): Parameter must be an array or an object that implements Countable in sizeof()함수를 사용할 때 array 혹은 object타입인지 체크를 하지 않아서 생기는 오류. 예시) sizeof($string); // Bad; if(is_array($stirng) || is_object($stirng)){ sizeof($string); // Good! } Server Language/PHP 2020. 3. 10. [Deprecated] session_is_registered() 대체 session_is_registered(), session_register() 는 deprecated되었다. 대체로 isset($_SESSION['session']), $_SEESION['session'] 으로 사용 가능. 예시) // Bad session_is_registered('seesion'); //Good isset($_SESSION['session']); Server Language/PHP 2020. 3. 10. [Deprecated] mysql 대체 [convert mysql to mysqli] mysql_connect mysql_select_db 등 mysql 함수가 deprecated되면서 mysqli 함수로 변경해 주어야 한다. 예시) //BAD $connect = mysql_connect($mysql_host,$mysql_user,$mysql_pw); mysql_select_db($mysql_db, $connect); mysql_query($query); mysql_affected_rows(); mysql_fetch_array($result); mysql_escape_string($string); //GOOD $connect =mysqli_connect($mysql_host,$mysql_user,$mysql_pw); mysqli_select_.. Server Language/PHP 2020. 3. 10. [Deprecated] $HTTP_GET_VARS 대체 // Bad; $HTTP_GET_VARS['get']; // Good; $_GET['get']; $HTTP_GET_VARS는 $_GET로 대체 가능 Server Language/PHP 2020. 3. 10. [Deprecated] $HTTP_POST_VARS 대체 $HTTP_POST_VARS는 $_POST로 대체 가능 // Bad $HTTP_POST_VARS['post']; // Good $_POST['post']; Server Language/PHP 2020. 3. 10. [Deprecated] $HTTP_COOKIE_VARS 대체 $HTTP_COOKIE_VARS는 $_COOKIE로 대체 가능 // Bad $HTTP_COOKIE_VARS['cookie']; // Good; $_COOKIE['cookie']; Server Language/PHP 2020. 3. 10. PHP Warning: Division by zero in PHP Warning: Division by zero in 주로 값이 0인 변수를 가지고 수식계산을 할 때 나타난다. 해결방법은 값이 0일때는 계산식에 들어가지 않게 분기처리 해준다. 예시) // Bad; $test = 0; $test2 = $test / 2; // Good! if($test != 0){ $test2 = $test / 2; } Server Language/PHP 2020. 3. 10. PHP Warning: Creating default object from empty value in PHP Warning: Creating default object from empty value in Object형식이 아닌 변수 혹은 empty value를 Object 형식으로 사용할 때 주로 나타나는 오류. 예시) // Bad; $stirng->etc->emai = 'email'; // Good! if(!isset($stirng->etc) || !is_object($stirng->etc)) { $stirng->etc = new stdclass(); $stirng->etc->emai = 'email'; } Server Language/PHP 2020. 3. 10. PHP Fatal error: Cannot use isset() on the result of an expression PHP Fatal error: Cannot use isset() on the result of an expression isset()함수를 사용할 때 안에 값에 변수에 $ 안붙였을 때 많이 발생. 예시) isset(test); // Bad; isset($test); // Good; Server Language/PHP 2020. 3. 9. PHP Warning: Use of undefined constant string - assumed 'string' PHP Warning: Use of undefined constant string - assumed 'string' 배열을 사용할 때 많이 나는 warning으로, 배열[string] 형태로 값을 사용 할 때 쿼테이션을 안붙여서 주로 발생. 예시) $string[test] = 'test' ; //Bad; $string["test"] = 'test' ; //Good! Server Language/PHP 2020. 3. 9. PHP Warning: Invalid argument supplied for foreach() in PHP Warning: Invalid argument supplied for foreach() in foreach 반복문을 사용 할 때, 매개변수 배열값에 대한 null 혹은 공백 사전 필터링을 하지 않아서 값이 없는 배열 혹은 Object로 반복문을 실행하여 나는 오류. 아래의 형식으로 고쳐 쓸 수 있다. 예시) // Bad; foreache($test as $key){ } // Good! if(isset($test) && (is_array($test) || is_object($test)) ){ foreache($test as $key){} } Server Language/PHP 2020. 3. 9. 이전 1 ··· 21 22 23 24 25 다음