PHP SG扩展管理Superglobals

A Simple PHP Superglobals Management

GitHub: github.com/yulonghu/sg

Introduction

SG is the same as PHP Superglobals, 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 PHP trim
  • 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/Off
sg.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
<?php
var_dump(sg::set('test', 'test apple'));
var_dump(sg::set('user.0.0', 'user 0 apple'));
var_dump(sg::set('user.0.1', 'user 1 apple'));
var_dump(sg::set('user.a.a', 'user a apple'));
var_dump(sg::set('user.a.b', 'user b apple'));复制代码

The above example will output:

bool(true)
bool(true)
bool(true)
bool(true)
bool(true)
复制代码
sg::get
<?php
var_dump(sg::get('test', 'test apple'));
var_dump(sg::get('user');
var_dump(sg::get('not_found', 'def');
var_dump(sg::get('user.1.2.3.4'));复制代码

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
<?php
var_dump(sg::has('test'));
var_dump(sg::has('not_found'));复制代码

The above example will output:

bool(true)
bool(false)
复制代码
sg::del
<?php
var_dump(sg::del('test'));
var_dump(sg::del('user.0.1'));
var_dump(sg::get('user');复制代码

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 PHP License v3.01


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
功能介绍 1、新增用户注册ip、注册城市 2、新增拉黑功能(不可使用红包模式) 3、新增限制地区使用红包模式(不可使用红包模式) 4、新增头像排序(新、热、总榜) 5、新增头像详情左右滑动下一张头像,可下载、生成海报、保存海报 6、新增微信聊天背景,详情左右滑动下一张图,可下载、生成海报、保存海报 7、新增(问答奖励、普通问答)可生成海报,保存海报 8、新增用户截图事件上报,后台用户列表中可查看用户截图次数,判断是否进行拉黑 9、优化九宫格文字模式,选择热门文字后,生成保存图片无效问题 10、优化九宫格趣味模式,生成保存图片顺序问题。 11、优化我的出题列表中,不显示普通问答模式 赚钱方式 1、赚取支付手续费 - 后台自定义手续费百分比 2、赚取提现手续费 - 用户红包金额提现,后台自定义提现手续费、提现低额度。 3、支付余额沉淀到平台 - 用户领到红包需提现才会发放资金,大多数用户忘记提现这部分收入 4、流量主 - 后台配置琉流量主 5、更多好玩 - 跳转其他小程序,导流利器。 注意事项: 1、程序含有社交红包,需要设置社交红包栏目,需要电信增值许可证 2、后台可关闭红包问答模式,或者开启禁止封地区使用红包问答模式 3、可关闭红包问答模式,选择休闲娱乐栏目上线。 4、支持个人主体、企业主体;(个人主体关闭红包模式即可)
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值