分類:PHP

Sublime Text PHP開發設定檔

安裝intelephense lsp server

npm install -g intelephense

sublimetext 安裝套件 LSP-intelephens

LSP-intelephense 設定

{
    "schemes": ["file", "buffer"],
    "auto_complete_selector": "punctuation.accessor | punctuation.definition.variable | punctuation.separator.namespace | punctuation.definition.tag.begin",
    "initializationOptions": {
        "clearCache": false,
        // "storagePath": "${temp_dir}/intelephense",
        // "globalStoragePath": "${home}/.intelephense",

        // if you want to use a premium license, you can either paste the key directly
        // or paste it into a file and provide its absolute path here
        // "licenceKey": "${packages}/User/intelephense-license.txt",
    },
    // @see configuration in https://github.com/bmewburn/vscode-intelephense/blob/master/package.json
    "settings": {
        // There are quite a lot of settings for intelephense...
        // For a full list, you can check the link above or just use LSP-json for autocompletion.

        // Enable a code lens that shows an abstract and interface implementations count and command to peek locations.
        "intelephense.codeLens.implementations.enable": false,

        // Enable a code lens that shows method override count and command to peek locations.
        "intelephense.codeLens.overrides.enable": false,

        // Enable a code lens that indicates if a method has a parent implementation and command to peek location.
        "intelephense.codeLens.parent.enable": false,

        // Enable a code lens that shows a reference count and command to peek locations.
        "intelephense.codeLens.references.enable": false,

        // Enable a code lens that shows a trait usages count and command to peek locations.
        "intelephense.codeLens.usages.enable": false,

        // Resolves `ArrayAccess` and `Traversable` implementations that are unioned with a typed array to generic syntax. eg `ArrayAccessOrTraversable|ElementType[]` => `ArrayAccessOrTraversable<mixed, ElementType>`.
        "intelephense.compatibility.correctForArrayAccessArrayAndTraversableArrayUnionTypes": true,

        // Resolves `BaseClass|static` union types to `static` instead of `BaseClass`.
        "intelephense.compatibility.correctForBaseClassStaticUnionTypes": true,

        // Prefer `@psalm-` and `@phpstan-` prefixed `@return`, `@var`, `@param` tags when determining symbol types.
        "intelephense.compatibility.preferPsalmPhpstanPrefixedAnnotations": false,

        // Global namespace constants and functions will be fully qualified (prefixed with a backslash).
        "intelephense.completion.fullyQualifyGlobalConstantsAndFunctions": false,

        // Use declarations will be automatically inserted for namespaced classes, traits, interfaces, functions, and constants.
        "intelephense.completion.insertUseDeclaration": true,

        // The maximum number of completion items returned per request.
        "intelephense.completion.maxItems": 100,

        // PHP permits the calling of static methods using the object operator eg `$obj->myStaticMethod();`. If you would prefer not to have static methods suggested in this context then set this value to `false`. Defaults to `true`.
        "intelephense.completion.suggestObjectOperatorStaticMethods": true,

        // Method and function completions will include parentheses and trigger parameter hints.
        "intelephense.completion.triggerParameterHints": true,

        // Enables argument count diagnostics.
        "intelephense.diagnostics.argumentCount": true,

        // Enables deprecated diagnostics.
        "intelephense.diagnostics.deprecated": true,

        // Enables duplicate symbol diagnostics.
        "intelephense.diagnostics.duplicateSymbols": true,

        // Enables diagnostics in embedded languages.
        "intelephense.diagnostics.embeddedLanguages": true,

        // Enables diagnostics.
        "intelephense.diagnostics.enable": true,

        // Enables reporting of problems associated with method and class implementations. For example, unimplemented methods or method signature incompatibilities.
        "intelephense.diagnostics.implementationErrors": true,

        // Enables reporting of various language constraint errors.
        "intelephense.diagnostics.languageConstraints": true,

        // This setting turns off type checking for the `mixed` type. This is useful for projects that may have incomplete or innacurate typings. Set to `false` to make type checking more thorough by not allowing `mixed` to satisy any type constraint. This setting has no effect when `relaxedTypeCheck` is `true`.
        "intelephense.diagnostics.noMixedTypeCheck": true,

        // This setting makes type checking less thorough by allowing contravariant (wider) types to also satisfy a type constraint. This is useful for projects that may have incomplete or innacurate typings. Set to `false` for more thorough type checks. When this setting is `true`, the `noMixedTypeCheck` setting is ignored.
        "intelephense.diagnostics.relaxedTypeCheck": true,

        // Controls when diagnostics are run.
        //  - onType: Diagnostics will run as changes are made to the document.
        //  - onSave: Diagnostics will run when the document is saved.
        "intelephense.diagnostics.run": "onType",

        // Enables diagnostics on type compatibility of arguments, property assignments, and return statements where types have been declared.
        "intelephense.diagnostics.typeErrors": true,

        // Enables undefined class constant diagnostics.
        "intelephense.diagnostics.undefinedClassConstants": true,

        // Enables undefined constant diagnostics.
        "intelephense.diagnostics.undefinedConstants": true,

        // Enables undefined function diagnostics.
        "intelephense.diagnostics.undefinedFunctions": true,

        // Enables undefined method diagnostics.
        "intelephense.diagnostics.undefinedMethods": true,

        // Enables undefined property diagnostics.
        "intelephense.diagnostics.undefinedProperties": true,

        // DEPRECATED. Use the setting for each symbol category.
        "intelephense.diagnostics.undefinedSymbols": true,

        // Enables undefined class, interface and trait diagnostics.
        "intelephense.diagnostics.undefinedTypes": true,

        // Enables undefined variable diagnostics.
        "intelephense.diagnostics.undefinedVariables": true,

        // Enables unexpected token diagnostics.
        "intelephense.diagnostics.unexpectedTokens": true,

        // Enables unused variable, private member, and import diagnostics.
        "intelephense.diagnostics.unusedSymbols": true,

        // The directory of the entry point to the application (directory of index.php). Can be absolute or relative to the workspace folder. Used for resolving script inclusion and path suggestions.
        "intelephense.environment.documentRoot": "",

        // The include paths (as individual path items) as defined in the include_path ini setting or paths to external libraries. Can be absolute or relative to the workspace folder. Used for resolving script inclusion and/or adding external symbols to folder.
        "intelephense.environment.includePaths": [],

        // A semver compatible string that represents the target PHP version. Used for providing version appropriate suggestions and diagnostics. PHP 5.3.0 and greater supported.
        "intelephense.environment.phpVersion": "8.3.0",

        // When enabled '<?' will be parsed as a PHP open tag. Defaults to true.
        "intelephense.environment.shortOpenTag": true,

        // Configure glob patterns to make files available for language server features. Inherits from files.associations.
        "intelephense.files.associations": [
            "*.php",
            "*.phtml"
        ],

        // Configure glob patterns to exclude certain files and folders from all language server features. Inherits from files.exclude.
        "intelephense.files.exclude": [
            "**/.git/**",
            "**/.svn/**",
            "**/.hg/**",
            "**/CVS/**",
            "**/.DS_Store/**",
            "**/node_modules/**",
            "**/bower_components/**",
            "**/vendor/**/{Tests,tests}/**",
            "**/.history/**",
            "**/vendor/**/vendor/**"
        ],

        // Maximum file size in bytes.
        "intelephense.files.maxSize": 1000000,

        // Controls formatting style of braces
        //  - per: PHP-FIG PER-CS style. A mix of Allman and K&R. https://www.php-fig.org/per/coding-style/
        //  - allman: Allman. Opening brace on the next line.
        //  - k&r: K&R (1TBS). Opening brace on the same line.
        "intelephense.format.braces": "per",

        // Enables formatting.
        "intelephense.format.enable": true,

        // DEPRECATED. Don't use this. Go to command palette and search for enter licence key.
        "intelephense.licenceKey": "",

        // Maximum memory (in MB) that the server should use. On some systems this may only have effect when runtime has been set. Minimum 256.
        "intelephense.maxMemory": 0,

        // An object that describes the format of generated class/interface/trait phpdoc. The following snippet variables are available: SYMBOL_NAME; SYMBOL_KIND; SYMBOL_TYPE; SYMBOL_NAMESPACE.
        "intelephense.phpdoc.classTemplate": {
            "summary": "$1",
            "tags": [
                "@package ${1:$SYMBOL_NAMESPACE}"
            ]
        },

        // An object that describes the format of generated function/method phpdoc. The following snippet variables are available: SYMBOL_NAME; SYMBOL_KIND; SYMBOL_TYPE; SYMBOL_NAMESPACE.
        "intelephense.phpdoc.functionTemplate": {
            "summary": "$1",
            "tags": [
                "@param ${1:$SYMBOL_TYPE} $SYMBOL_NAME $2",
                "@return ${1:$SYMBOL_TYPE} $2",
                "@throws ${1:$SYMBOL_TYPE} $2"
            ]
        },

        // An object that describes the format of generated property phpdoc. The following snippet variables are available: SYMBOL_NAME; SYMBOL_KIND; SYMBOL_TYPE; SYMBOL_NAMESPACE.
        "intelephense.phpdoc.propertyTemplate": {
            "summary": "$1",
            "tags": [
                "@var ${1:$SYMBOL_TYPE}"
            ]
        },

        // Adds `@return void` to auto generated phpdoc for definitions that do not return a value.
        "intelephense.phpdoc.returnVoid": true,

        // 
        //  - snippet: Auto generated phpdoc is returned in snippet format. Templates are partially resolved by evaluating phpdoc specific variables only.
        //  - text: Auto generated phpdoc is returned as plain text. Templates are resolved completely by the server.
        "intelephense.phpdoc.textFormat": "snippet",

        // Fully qualified names will be used for types when true. When false short type names will be used and imported where appropriate. Overrides intelephense.completion.insertUseDeclaration.
        "intelephense.phpdoc.useFullyQualifiedNames": false,

        // Glob patterns matching files and folders that should be excluded from references search.
        "intelephense.references.exclude": [
            "**/vendor/**"
        ],

        // Glob patterns matching files and folders that should be excluded when renaming symbols. Rename operation will fail if the symbol definition is found in the excluded files/folders.
        "intelephense.rename.exclude": [
            "**/vendor/**"
        ],

        // Controls the scope of a namespace rename operation.
        //  - single: Only symbols defined in the current file are affected. For example, this makes a rename of a namespace the equivalent of a single move class operation.
        //  - all: All symbols that share this namespace, not necessarily defined in the current file will be affected. For example it would move all classes that share this namespace to the new namespace.
        "intelephense.rename.namespaceMode": "single",

        // Path to a Node.js executable. Use this if you wish to use a different version of Node.js. Defaults to Node.js shipped with VSCode.
        "intelephense.runtime": "",

        // Configure stub files for built in symbols and common extensions. The default setting includes PHP core and all bundled extensions.
        "intelephense.stubs": [
            "apache",
            "bcmath",
            "bz2",
            "calendar",
            "com_dotnet",
            "Core",
            "ctype",
            "curl",
            "date",
            "dba",
            "dom",
            "enchant",
            "exif",
            "FFI",
            "fileinfo",
            "filter",
            "fpm",
            "ftp",
            "gd",
            "gettext",
            "gmp",
            "hash",
            "iconv",
            "imap",
            "intl",
            "json",
            "ldap",
            "libxml",
            "mbstring",
            "meta",
            "mysqli",
            "oci8",
            "odbc",
            "openssl",
            "pcntl",
            "pcre",
            "PDO",
            "pdo_ibm",
            "pdo_mysql",
            "pdo_pgsql",
            "pdo_sqlite",
            "pgsql",
            "Phar",
            "posix",
            "pspell",
            "random",
            "readline",
            "Reflection",
            "session",
            "shmop",
            "SimpleXML",
            "snmp",
            "soap",
            "sockets",
            "sodium",
            "SPL",
            "sqlite3",
            "standard",
            "superglobals",
            "sysvmsg",
            "sysvsem",
            "sysvshm",
            "tidy",
            "tokenizer",
            "xml",
            "xmlreader",
            "xmlrpc",
            "xmlwriter",
            "xsl",
            "Zend OPcache",
            "zip",
            "zlib"
        ],

        // Anonymous usage and crash data will be sent to Azure Application Insights. Inherits from telemetry.enableTelemetry.
        "intelephense.telemetry.enabled": null,

        // Traces the communication between VSCode and the intelephense language server.
        "intelephense.trace.server": "off",
        "statusText": "{% if server_version %}v{{ server_version }}{% endif %}",
    },
    "selector": "embedding.php",
    "priority_selector": "source.php",
}

PHP empty, is_null, isset 判斷結果列表

empty判斷值在不在,isset判斷變數在不在,兩個不同屬性

表達式			GETTYPE()	EMPTY()		IS_NULL()	ISSET()	  	BOOLEAN : IF($X)
$x = "";		string		TRUE		FALSE		TRUE		FALSE
$x = null;		NULL		TRUE		TRUE		FALSE		FALSE
var $x;			NULL		TRUE		TRUE		FALSE		FALSE
$x is undefined	        NULL		TRUE		TRUE		FALSE		FALSE
$x = array();	        array		TRUE		FALSE		TRUE		FALSE
$x = false;		boolean		TRUE		FALSE		TRUE		FALSE
$x = true;		boolean		FALSE		FALSE		TRUE		TRUE
$x = 1;			integer		FALSE		FALSE		TRUE		TRUE
$x = 42;		integer		FALSE		FALSE		TRUE		TRUE
$x = 0;			integer		TRUE		FALSE		TRUE		FALSE
$x = -1;		integer		FALSE		FALSE		TRUE		TRUE
$x = "1";		string		FALSE		FALSE		TRUE		TRUE
$x = "0";		string		TRUE		FALSE		TRUE		FALSE
$x = "-1";		string		FALSE		FALSE		TRUE		TRUE
$x = "php";		string		FALSE		FALSE		TRUE		TRUE
$x = "true";	        string		FALSE		FALSE		TRUE		TRUE
$x = "false";	        string		FALSE		FALSE		TRUE		TRUE

參考連結

http://php.net/manual/zh/types.comparisons.php

php-fpm和nginx 權限設定問題

php-fpm

修改/etc/php5/fpm/pool.d/www.conf

user = www-data 改為 user = ken

group = www-data 改為 group = user

listen.owner = www-data 改為 listen.owner = user

listen.group = www-data 改為 listen.group = user

nginx

修改/etc/nginx/nginx.conf

user www-data; 改為 user;

這樣就沒權限問題了

PHP Laravel 安裝設定 筆記

安裝的方式有很多種

我採用的是直接從github下載最新版解壓縮後執行

php composer.phar install

如果是Linux 環境下安裝記的把app/storage目錄設成伺服器可讀寫的權限

建議是直接設777比較省事

環境變數設定

記的修改bootstrap/start.php

$env = $app->detectEnvironment(function()
{
    return $_SERVER['MY_LARAVEL_ENV'];
});

設成動態的去判斷環境變數

不過這樣一來在CLI上指令就需加上

env MY_LARAVEL_ENV=development

這樣才能讀到config的設定檔

在start也是讀LARAVEL_ENV的設定

Nignx設定

server {
    listen 80;
    root /home/kfrico/www/black/public;
    index index.html index.htm index.php;
    server_name black.ipushs.com;

    location / {
        try_files $uri $uri/ /index.php?$query_string;
    }

    location ~ \.php {
        fastcgi_param LARAVEL_ENV "development";

        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass unix:/var/run/php5-fpm.sock;
        fastcgi_index index.php;
        include fastcgi_params;
    }
}

 

PHP ob_start() 使用方法 靜態模版介紹[轉載]

用PHP的ob_start();控制您的瀏覽器cache!

Output Control 函數可以讓你自由控制腳本中數據的輸出。它非常地有用,特別是對於:當你想在數據已經輸出後,再輸出文件頭的情況。輸出控制函數不對使用 header() 或 setcookie(), 發送的文件頭信息產生影響,只對那些類似於 echo() 和 PHP 代碼的數據塊有作用。

我們先舉一個簡單的例子,讓大家對Output Control有一個大致的印象:
Example 1.

<?php
ob_start(); //打開緩衝區
echo "Hellon"; //輸出
header("location:index.php"); //把瀏覽器重定向到index.php
ob_end_flush();//輸出全部內容到瀏覽器
?>

繼續閱讀