[PHP] PHP basic > Web/PHP/API

본문 바로가기
사이트 내 전체검색

Web/PHP/API

[PHP] PHP basic

페이지 정보

작성자 sbLAB 댓글 0건 조회 3,738회 작성일 22-12-26 19:15

본문

Full PHP 8 Tutorial 

https://github.com/ggelashvili/learnphptherightway-outline 

https://www.youtube.com/watch?v=sVbEyFZKgqk&list=PLr3d3QYzkw2xabQRUpcZ_IBk9W50M9pe- 


array option append

    <?php

    $origin_array=['0'=>'v0','1'=>'v1'];

    function optionTest(array $options = [])
    {
        $options += [
            '3' => 'v3',
            '4' => 'v4',
            '5' => 'v5',
            '6' => 'v6',
            '7' => false,
        ];
        return $options;
    }

    var_dump(optionTest($origin_array));

    // array(7) {
    //   [0] =>
    //   string(2) "v0"
    //   [1] =>
    //   string(2) "v1"
    //   [3] =>
    //   string(2) "v3"
    //   [4] =>
    //   string(2) "v4"
    //   [5] =>
    //   string(2) "v5"
    //   [6] =>
    //   string(2) "v6"
    //   [7] =>
    //   bool(false)

 



PHP __invoke()

https://www.php.net/manual/en/language.oop5.magic.php#object.invoke 

https://silnex.github.io/blog/php-invoke-method/ 


PHP Magic Methods 

https://velog.io/@hyeonseop/PHP-OOP-4.-%EB%A7%A4%EC%A7%81-%EB%A9%94%EC%84%9C%EB%93%9C-Magic-Methods 


PHP DI

https://www.slimframework.com/docs/v4/concepts/di.html (Slim4) 

https://stackhoarder.com/2019/08/04/didependency-injection-%EB%B6%80%ED%84%B0-dip-%EA%B9%8C%EC%A7%80-%EC%98%88%EC%A0%9C%EB%A1%9C-%EC%9D%B5%ED%9E%88%EC%9E%90/ 

https://akrabat.com/dependency-injection-in-slim-4/ 

http://sebom.com/gb/bbs/board.php?bo_table=gallery&wr_id=67 


PDO Fetch Modes 

https://phpdelusions.net/pdo/fetch_modes#FETCH_OBJ 


[PHP] 클로저(Closure)

https://spiderwebcoding.tistory.com/11

https://m.blog.naver.com/maestrois/221600444469 


callable in PHP  - (클래스,메서드, 함수)를 파라미터 처럼 사용가능하게 함. (Callable은 익명, 일반 function 모두 사용가능)

https://stackoverflow.com/questions/29730720/type-hinting-difference-between-closure-and-callable 

<?php
function callFunc1(Closure $closure) {
    $closure();
}

function callFunc2(Callable $callback) {
    $callback();
}

function xy() {
    echo 'Hello, World!';
}

callFunc1("xy");
// Catchable fatal error: Argument 1 passed to callFunc1() must be an instance of Closure, string given

callFunc2("xy"); // Hello, World!


라우팅에 자주사용됨.

function post($pattern, callable $handler) {

    $this->routes['post'][$pattern] = $handler;

    return $this;

}


https://stackoverflow.com/questions/54166666/what-does-the-keyword-callable-do-in-php 


function helloWorld(){
    echo 'Hello World!';
}
function handle(callable $fn){
    $fn(); // We know the parameter is callable then we execute the function.
}
handle('helloWorld'); // Outputs: Hello World!



Http Method(GET, POST, PUT, DELETE) 

https://velog.io/@yh20studio/CS-Http-Method-%EB%9E%80-GET-POST-PUT-DELETE


 GET

 POST

 PUT

 DELETE

 SELECT

 INSERT

UPDATE 

DELETE 

 /user/1 

  /user

 /user/1 

 /user/1

URL 

 body : {date : "example"}

Content-Type : "application/json"

body : {date : "update example"}

Content-Type : "application/json" 

URL 


PDO

https://inpa.tistory.com/entry/PHP-%F0%9F%93%9A-DB-%EB%8B%A4%EB%A3%A8%EA%B8%B0-MySQL-PDO


PHP 3분 핵심 요약집 

https://wikidocs.net/book/5793 


네임스페이스 - autoload 

55 프로젝트 

2b479cc99d321a62b0413080fffff01a_1672053831_8063.jpg
 

[brus 폴더생성 후 그안에 Sample.php]  = D:/55/brus/Sample.php

<?php
namespace brus; //brus 네임스페이스 선언

class Sample
{
    // member variable
    private $name;
    private $age;

    // constructor
    public function __construct() //php 컨스트럭터
    {
        $this->name = "brus";
        $this->age = "10";
    }

    // method
    public function tell()
    {
        echo "my name is {$this->name} .";
        echo " and my age is {$this->age} .";
    }

    // method. return $this
    public function add_age($age)
    {
        $this->age += $age;
        return $this;
    }

    // static method
    public static function factory() //static factory =>이 클래스 인스턴스 리턴( :: 로 직접 접근가능 )
    {
        return new Sample();
    }
}



[루트 폴더에 autoload.php]  = D:/55/autoload.php

<?php

spl_autoload_register(function ($class) {    //spl_autoload_register 함수로 오토로드할 클래스 등록
 include "$class.php"; //클래스 호출될때 호출 클래스명과 동일한 클래스명.php 파일 자동 include
 });

use brus\Sample; //아래에서 사용할 brus 네임스페이스의 Sample 클래스 사용 알림
$sample = Sample::factory();
$sample->tell();

echo "<br />";
$sample = new brus\Sample(); //이렇게 new brus\Sample(); 하면 위에 use brus\Sample; 필요없음.
$sample->add_age(5)->tell();
 


[Result]

http://localhost/55/autoload.php

my name is brus. and my age is 10 .

my name is brus. and my age is 15 .


PHP 8.1: Enums 

https://php.watch/versions/8.1/enums 

https://www.php.net/manual/en/language.enumerations.basics.php 


User-defined functions - function 안에 function 있을때 function call

https://www.php.net/manual/en/functions.user-defined.php 



댓글목록

등록된 댓글이 없습니다.

회원로그인

접속자집계

오늘
303
어제
286
최대
1,279
전체
204,248

그누보드5
Copyright © sebom.com All rights reserved.