小编Eko*_*pha的帖子

意外的PHP切换行为

我正在运行一些单元测试,并使用我正在使用的switch语句遇到了意外行为.我已经隔离了下面的条件.

function test($val)
{
    switch($val)
    {
       case 'a':
       case 'b':
          return 'first';
       break;
       case 'c':
          return 'second';
       break;
       default:
          return 'third';
    }
}
Run Code Online (Sandbox Code Playgroud)

这是我的第一轮测试:

test('a') => 'first'
test('b') => 'first'
test('c') => 'second'
test('d') => 'third'    
test('0') => 'third'
test('1') => 'third'
test('true')  => 'third'
test('false') => 'third'
Run Code Online (Sandbox Code Playgroud)

这很明显吧?好了,现在看看这些:

test(0)     => 'first'  // expected 'third'
test(1)     => 'third'
test(true)  => 'first'  // expected 'third'
test(false) => 'third'
test(null)  => 'third'
test([])    => 'third'
Run Code Online (Sandbox Code Playgroud)

什么是奇怪的结果与0和真?如果1/true和0/false返回相同的值,我会把它写成松散的输入.但他们没有!

如果我将值转换为(字符串),则交换机按预期工作.

test((string) 0)     => 'third'
test((string) …
Run Code Online (Sandbox Code Playgroud)

php switch-statement

7
推荐指数
1
解决办法
146
查看次数

我在apache日志中一直看到+ - +,它是什么?

我正在查看我的apache服务器日志,几乎总是当有人在扫描服务器的漏洞时,我总是在他们的查询字符串中看到这个...

+ - +

比如下面的各种例子......

.
.
.
/includes/usercp_register.php?phpbb_root_path=1'+--+?
/includes/profilcp_constants.php?module_root_path=1'+--+?
/includes/functions_user_viewed_posts.php?phpbb_root_path=1'+--+?
/includes/orderSuccess.inc.php?&glob=1&cart_order_id=1&glob[rootDir]=1'+--+
.
.
.
Run Code Online (Sandbox Code Playgroud)

我知道他们正在扫描流行的漏洞,但我想知道的是+ - +的目的是什么?

我想把它用作我可以过滤使用fail2ban的东西

apache security

5
推荐指数
1
解决办法
93
查看次数

根据引用类型对 ~/.bash_profile 别名中的 pwd 进行不同评估

这是在 OSX El Capitan 上,但也发生在我的 Ubuntu 别名中。

我遇到了一个问题,我创建的别名将工作目录传递给 docker 容器。

这将不起作用(无论我在哪个目录中,始终为 $(pwd) 传递 ~/Users/username ):

alias phpqa="docker run --rm -u $UID -v $(pwd):/app eko3alpha/docker-phpqa"
Run Code Online (Sandbox Code Playgroud)

作品:

alias phpqa='docker run --rm -u $UID -v $(pwd):/app eko3alpha/docker-phpqa'
Run Code Online (Sandbox Code Playgroud)

但是,当传入错误的路径时,我的脚本中开始出现意外错误。所以我做了一个实验。我将这两个别名添加到我的 ~/.bash_profile 中。

alias getpath="echo $(pwd)"
alias getpath2='echo $(pwd)'
Run Code Online (Sandbox Code Playgroud)

我注销然后重新登录。

更改目录:

$ cd /Users/username/correct/path/to/project
Run Code Online (Sandbox Code Playgroud)

执行两个别名:

$ getpath
/Users/username

$ getpath2
/Users/username/correct/path/to/project
Run Code Online (Sandbox Code Playgroud)

带双引号的别名总是返回用户主目录,而带单引号的别名返回当前目录。有人可以解释为什么会这样吗?

macos shell alias osx-elcapitan

2
推荐指数
1
解决办法
307
查看次数

标签 统计

alias ×1

apache ×1

macos ×1

osx-elcapitan ×1

php ×1

security ×1

shell ×1

switch-statement ×1