donglong7338 2014-07-28 22:05
浏览 33
已采纳

为什么PHP双箭头运算符'=>'会停止执行代码

I'm trying to create a web app and I want to make key value pair array. Like this:

<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8"></meta>
  <link rel="stylesheet" type="text/css" href="css/style.css">
  <title></title>
  <script type="text/javascript" charset="utf-8" src="lib/jquery-1.11.0.js"></script>
  <script type="text/javascript" charset="utf-8" src="script/main.js"></script>
</head>


<?php

$data = array('grant_type' => $authorization_code);

// more code goes here

?>

  <div class="container">

  </div>

</body>

</html>

For some reason, the code above just prints $authorization_code); // more code goes here ?>

So it seems that the execution stops everytime I insert '=>' to the code. This occurs even if '=>' is commented.

Before down voting this please consider I already feel incredibly dumb and I really, really did not find an answer to this by Googling.

EDIT

Added full source.

  • 写回答

1条回答 默认 最新

  • douri4459 2014-07-28 22:08
    关注

    You haven't quoted either of those values, so PHP is treating them as undefined constants.

    Try

    $data = array('grant_type' => $authorization_code);
    

    or whatever it really should be instead.

    php > $data = array(foo => bar);
    PHP Notice:  Use of undefined constant foo - assumed 'foo' in php shell code on line 1
    PHP Notice:  Use of undefined constant bar - assumed 'bar' in php shell code on line 1
    php > define('foo', 'hello');
    php > define('bar', 'world');
    php > $data = array(foo => bar);
    php > var_dump($data);
    array(1) {
      ["hello"]=>
      string(5) "world"
    }
    

    As far as execution stopping goes, => shouldn't be a PHP block sentinel value. only ?> would "shut off" php.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 steam下载游戏占用内存
  • ¥15 树莓派5怎么用camera module 3啊
  • ¥20 java在应用程序里获取不到扬声器设备
  • ¥15 echarts动画效果的问题,请帮我添加一个动画。不要机器人回答。
  • ¥15 Attention is all you need 的代码运行
  • ¥15 一个服务器已经有一个系统了如果用usb再装一个系统,原来的系统会被覆盖掉吗
  • ¥15 使用esm_msa1_t12_100M_UR50S蛋白质语言模型进行零样本预测时,终端显示出了sequence handled的进度条,但是并不出结果就自动终止回到命令提示行了是怎么回事:
  • ¥15 前置放大电路与功率放大电路相连放大倍数出现问题
  • ¥80 部署运行web自动化项目
  • ¥15 腾讯云如何建立同一个项目中物模型之间的联系