博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
PHP SG扩展管理Superglobals
阅读量:6078 次
发布时间:2019-06-20

本文共 2302 字,大约阅读时间需要 7 分钟。

A Simple PHP Superglobals Management

GitHub:

Introduction

SG is the same as PHP , Management global variables are $_GET, $_POST, $_COOOKIE, $_SERVER, $_FILES, User-defined global variables. Use SG can save a lot of PHP code. 

Features

  • Simple, Fast, Lightweight
  • Access global variable zero-copy
  • Strip whitespace with
  • Solve problems with PHP undefined series (Undefined variable, Undefined offset)

Install

Requirements

  • PHP 7.0 +

DownLoad

git clone https://github.com/yulonghu/sg.git复制代码

Compile SG in Linux

$ /path/to/php7/bin/phpize$ ./configure --with-php-config=/path/to/php7/bin/php-config$ make && make install复制代码

Add the follow information to your php.ini

extension=sg.so[sg]sg.enable = On复制代码

Restart the web server

Methods

mixed sg::get(string $key [, mixed $default_value = null])bool sg::set(string $key, mixed $value)bool sg::has(string $key)bool sg::del(string $key)复制代码

Inis

sg.enable = On/Offsg.auto_trim = On/Off ; Strip whitespace with PHP trim复制代码

Example

PHP Superglobals

OLD GET METHOD (Short) NEW GET METHOD
$_GET['key'] sg::get('g.key')
$_POST['key'] sg::get('p.key')
$_COOKIE['key'] sg::get('c.key')
$_SERVER['key'] sg::get('s.key')
$_FILES['key'] sg::get('f.key')
OLD GET METHOD (Long) NEW GET METHOD
$_GET['key']['key1']['key2'] sg::get('g.key.key1.key2')
$_POST['key']['key1']['key2'] sg::get('p.key.key1.key2')
$_COOKIE['key']['key1']['key2'] sg::get('c.key.key1.key2')
$_SERVER['key']['key1']['key2'] sg::get('s.key.key1.key2')
$_FILES['key']['key1']['key2'] sg::get('f.key.key1.key2')

User-defined global variables

sg::set

The above example will output:

bool(true)bool(true)bool(true)bool(true)bool(true)复制代码

sg::get

The above example will output:

string(10) "test apple"array(2) {  [0]=>  array(2) {    [0]=>    string(12) "user 0 apple"    [1]=>    string(12) "user 1 apple"  }  ["a"]=>  array(2) {    ["a"]=>    string(12) "user a apple"    ["b"]=>    string(12) "user b apple"  }}string(3) "def"NULL复制代码

sg::has

The above example will output:

bool(true)bool(false)复制代码

sg::del

The above example will output:

bool(true)bool(true)array(2) {  [0]=>  array(1) {    [0]=>    string(12) "user 0 apple"  }  ["a"]=>  array(2) {    ["a"]=>    string(12) "user a apple"    ["b"]=>    string(12) "user b apple"  }}复制代码

License

SG is open source software under the

转载地址:http://wnsgx.baihongyu.com/

你可能感兴趣的文章
Swift中的协议
查看>>
搬进Github
查看>>
oracle子查询
查看>>
cocos2d-x-2.2.5项目创建--命令行创建
查看>>
Risk(最短路)
查看>>
ngRoute 和 ui.router 的使用方法和区别
查看>>
IndiaHacks 2016 - Online Edition (Div. 1 + Div. 2) D. Delivery Bears 二分+网络流
查看>>
struts2中页面访问action的url问题,或许很简单
查看>>
EF Code First 学习笔记:关系
查看>>
认识Java Core和Heap Dump
查看>>
【转】所需即所获:像 IDE 一样使用 vim
查看>>
[navicat] Navicat for Oracle Cannot load OCI DLL
查看>>
红米NOTE应用闪退(包括系统设置等各种界面)问题解决经历
查看>>
五种方式让你在java中读取properties文件内容不再是难题
查看>>
php之aop实践
查看>>
CentOS7安装配置redis-3.0.0
查看>>
python安装libxml2和pyquery
查看>>
Oracle 权限(grant、revoke)
查看>>
Prototype 原型模式 复制 Cloneable clone
查看>>
ios随机数
查看>>