3

我正在探索 php,我发现了system.outsystemout。php 说它们是字符串,但它们的行为不像字符串。这里有些例子。

    system.out.print('test');
    //output
    test

    system.out.var_dump('system.out');
    // output
    string(9) "systemout"


    systemout.var_dump('test');
    // output 

string(4) "test"

这是语言错误吗?

4

2 回答 2

5

让我在代码中这样说:

in.fact.you.can.concat.many.undefined.constants.with.any.func.print('.');

如果你启用了错误报告,php 会通知你许多未定义的常量,它们将被视为字符串,因此将被视为:

'in'.'fact'.'you'.'can'.'concat'.'many'.'undefined'.'constants'.'with'.'any'.'func'.print('.');

产生所需输出的唯一方法是函数调用。此函数的返回值连接到未定义常量的字符串,并且什么也不做。

于 2013-03-24T20:19:30.133 回答
-1
//i can tell what you are trying to do.is to dumb some vars to console.
//System.out.printLn does not exist in php

//there are other tools like firephp but this is the simplest method to log vars to console
//use the following function instead in php
function phpconsole($label='var',$x){
?>
 <script type="text/javascript">
   console.log('<?php echo ($label)?>');
   console.log('<?php echo json_encode($x)?>');
  </script>
 <?php
}
//use it like this
$salary = 500;
phpconsole('salary:',$salary);

$arr = array('aaa','bbb','ccc');
phpconsole('arr:',$arr);//it will accept any datatype and dumb it to console
于 2014-03-12T15:07:31.963 回答