syntax-error 相关问题

当程序不遵循编程语言的语法规则时,会发生语法错误。


写一个程序,该程序占用三个小写字符并以字母顺序输出字符

编写一个程序,该程序会收集三个小写字符并按字母顺序输出字符。 提示:订购三个字符需要六个排列。如果输入是CBA,则输出wil ...

回答 1 投票 0



我如何在php中修复“未定义变量”错误? today,我已经开始学习PHP。而且,我创建了第一个PHP文件来测试不同的变量。您可以看到我的文件如下。

我在浏览器中运行此文件时发现了以下错误。 notice:未定义的变量:x in/opt/lampp/htdocs/anand/php/php/index.php in19行 NOTICE:未定义的变量:y in/opt/lampp/htdocs/anand/php/php/index.php在第29行上 我如何解决有关它的问题? 第一个错误(不确定)是因为默认情况下没有将全球范围导入到功能中(而不是“超级全球”,那是)。 您需要告诉您的功能您是在引用全局变量$x:: $x php,PHP无法判断您是否正在用同名局部变量遮蔽全局变量。 第二误差(function myTest() { global $x; // $x refers to the global variable $y=10; // local scope echo "<p>Test variables inside the function:<p>"; echo "Variable x is: $x"; echo "<br>"; echo "Variable y is: $y"; } 是未定义的),是因为本地范围就是本地。它的全部要点是$y不会从功能中“泄漏”。当然,您无法以后在代码中访问$y在定义其定义的函数之外。如果可以的话,它与全球没有什么不同。 $y 您正在遇到第一个错误,因为变量$ a无法访问全局变量的值,除非您明确声明函数内部声明。 示例#1使用全局 <?php $a = 1; /* Global scope */ function test() { echo $a; /* Reference to local scope variable */ } test(); ?> 以及您遇到的最后一个错误是因为$y在函数内定义了global $a,因此其范围仅限于该函数。 对于详细的解释,请阅读宽可变范围。 有两种使用变量globally:的情况 使用该变量的单个副本并从任何地方进行修改,即从函数内部或外部进行修改,即在全局范围内进行修改。在这种情况下,您需要在允许的函数集<?php $a = 1; $b = 2; function Sum() { global $a, $b; // If you want to access a global variable, // you have to use the 'global' keyword $b = $a + $b; } Sum(); echo $b; ?> 形式中声明。 在情况下,您需要使用用于全局变量的same标识符的单个函数的局部变量(即所有函数之外的变量);在这种情况下,您有两个变量具有相同名称,即该功能一个本地和一个全局。然后,您需要使用superglobal变量mytest()即所有全局变量的数组。我个人更喜欢这种方法来制作高效代码; 以下是两者的代码。 代码1(使用全局声明) global $x; 代码2(使用$ GLOBALS []数组) $GLOBALS SET$ x作为全球,喜欢 <?php $x = 5; // Global scope function myTest() { $y = 10; // Local scope global $x; echo "<p>Test variables inside the function:<p>"; echo "Variable x in global scope is: $x"; echo "<br>"; echo "Variable y is: $y"; } myTest(); echo "<p>Test variables outside the function:<p>"; echo "Variable x is: $x"; echo "<br>"; echo "Variable y is: $y"; ?> 或尝试以下操作: <?php $x = 5; // Global scope function myTest() { $y = 10; // Local scope $x = 23; echo "<p>Test variables inside the function:<p>"; echo "Variable x in global scope is: " . $GLOBALS['x']; echo "<br>Variable x in local scope is: $x"; echo "<br>"; echo "Variable y is: $y"; } myTest(); echo "<p>Test variables outside the function:<p>"; echo "Variable x is: $x"; echo "<br>"; echo "Variable y is: $y"; ?> 代码的行为是按预期的,但是如果您想在脚本上使用两个变量,请使用以下方式: global $x; 在php中,如果要在该函数中使用函数,则必须在函数中声明全局变量。 <?php $x = 5; // Global scope function myTest($x) { $y=10; // Local scope echo "<p>Test variables inside the function:<p>"; echo "Variable x is: $x"; echo "<br>"; echo "Variable y is: $y"; } myTest($x); echo "<p>Test variables outside the function:<p>"; echo "Variable x is: $x"; echo "<br>"; echo "Variable y is: $y"; ?> 通过在函数中宣布$ x全局,它将参考变量的全局版本。 您必须学习PHP中变量的范围。请参阅VariableScope. 在您的代码中,$ x是一个全局,因此,为了在函数开头访问函数中的该变量,即,即,即 <?php $x = 5; // Global scope function myTest(){ global $x; global $y; $y = 10; echo "<p>Test variables inside the function:<p>"; echo "Variable x is: $x"; echo "<br>"; echo "Variable y is: $y"; } myTest(); echo "<p>Test variables outside the function:<p>"; echo "Variable x is: $x"; echo "<br>"; echo "Variable y is: $y"; ?> 对于$ y,您要么通过检查isset($ y)跳过输出,要么在全局范围内分配默认值。 upput $ x在“ echo”中的“”中的“”中的“变量” $ x是:”。$ x; yii ase \ errorexception:undefined变量$启动in/var/www/tracktraf.online/frontend/frontend/controllers/telegramcontroller.php:197 堆栈跟踪: #0/var/www/tracktraf.online/frontend/controllers/telegramcontroller.php(197):yii ase \ errorhandler-> thanherror() #1 [内部功能]:前线

回答 4 投票 0

回答 0 投票 0

我应该在我的SQL案例语句中添加一个URL?

帐户状态的情况 但是我一直遇到错误

回答 2 投票 0


' 我正在尝试使用MQL5为Metatrader 5开发专家顾问(EA),但我一直遇到错误”(<' - open parenthesis expected

if (Bars < 3) <) - open parenthesis expected' for the following: if (Bars < 3) Here is a snip...

回答 1 投票 0

电源查询自定义列错误消息语法错误

有人可以帮助纠正我在这里创建的语法错误吗?

回答 1 投票 0



MYSQL触发失败:语法问题,infare,if和signal命令

问题描述 我正在尝试创建一个MySQL触发器来验证设备授权,然后再在表上插入(generic_table)。触发器检查设备是否与

回答 0 投票 0




为什么出乎意料的令牌显示?

有人可以查看我的代码,并告诉我为什么在第16行中遇到错误? 参见Codepen -codepen Calctotal:function(type){ sum = 0; data.allitems [type] .foreach(function(cur){...

回答 2 投票 0

uncaught syntaxerror:“ [对象对象]”在json.parse(<anonymous>)

Uncaught SyntaxError: "[object Object]" is not valid JSON at JSON.parse (<anonymous>) vendors~main.chunk.js:32926 The above error occurred in the <Home> component: at Home (http://localhost:3000/static/js/main.chunk.js:1640:99) at RenderedRoute (http://localhost:3000/static/js/vendors~main.chunk.js:131876:5) at Routes (http://localhost:3000/static/js/vendors~main.chunk.js:132298:5) at App at Router (http://localhost:3000/static/js/vendors~main.chunk.js:132236:15) at BrowserRouter (http://localhost:3000/static/js/vendors~main.chunk.js:130557:5) Consider adding an error boundary to your tree to customize error handling behavior. Visit https://reactjs.org/link/error-boundaries to learn more about error boundaries. console.<computed> @ vendors~main.chunk.js:32926 localhost/:1 Uncaught (in promise) SyntaxError: "[object Object]" is not valid JSON at JSON.parse (<anonymous>) at Home (main.chunk.js:1643:72) VM23:2 Uncaught ReferenceError: process is not defined

回答 3 投票 0

syntaxError:在react Native(activityIndicator.js)

我正在运行我的React Native项目时遇到以下错误:

回答 0 投票 0


最新问题
© www.soinside.com 2019 - 2025. All rights reserved.