我想知道为什么我的php程序在其他地方包含类时没有返回正确的TRUE FALSE值
它就是这样的
source: signup.php
class signup
{
function buildProfile()
{
if($logic){
$this->success = TRUE;
}else{
$this->success = FALSE;
}
}
function __construct()
{
$this->success = NULL;
$this->buildProfile
return $this->success;
}
}
Run Code Online (Sandbox Code Playgroud)
我在其他地方
include('signup.php');
$signup = new signup();
if($signup){
successFunction();
}else....
Run Code Online (Sandbox Code Playgroud)
但它并没有得到$ signup == true,它每次都变得虚假
if ($var == ($var1 || $var2))
{
...
}
Run Code Online (Sandbox Code Playgroud)
我正在考虑使用它,但我确定它是否有效,并且似乎没有某个地方可以检查.
它似乎在逻辑上与我一致,但我不确定,我没有东西可以在附近测试它.
如果它是有效的,那么其他主流语言支持这种构造.
编辑:比较是有效的,但不是我想的方式.
我试图做的实际上是我刚刚发现的in_array()函数.
假设result[11] == string.Empty(即result[11] = "")
if (result[11] == string.Empty) // this block works fine
{
user.Age = Int32.Parse(result[11]);
}
else
{
user.Age = null;
}
// the following line will throw exception
user.Age = (result[11] == string.Empty) ? (int?) null :
Int32.Parse(result[11]);
Run Code Online (Sandbox Code Playgroud)
System.FormatException未处理Message =输入字符串格式不正确.Source = mscorlib StackTrace:System.Number.StringToNumber(String str,NumberStyles options,NumberBuffer&number,>> >> NumberFormatInfo info,Boolean parseDecimal),位于System的System.Number.ParseInt32(String s,NumberStyles style,NumberFormatInfo info). Int32.Parse(String s)
对我来说,上面两个块是一样的.那为什么第一个工作而第二个不工作呢?
我的代码如下;
<select class="reg_field_field" id="user_address_state" name="user_address_state" tabindex="7">
<option value="AL" <?php if($state=='AL') echo 'selected';?>/>Alabama</option>
<option value="AK" <?php if($state=='AK') echo 'selected';?>/>Alaska</option>
<option value="AZ" <?php if($state=='AZ') echo 'selected';?>/>Arizona</option>
....
</select>
Run Code Online (Sandbox Code Playgroud)
结果显示我的状态名称,它显示"通知:未定义的变量......".
我试过这个在其他服务器上工作,可能是php.ini配置??? 什么可以在php.ini上?
感谢您的任何帮助
麦酒
我正在尝试建立一个条件系统,以编程方式检测浏览器(使用USER_AGENT字符串)和平台(使用PHP-Mobile-Detect).我目前的设置大致如下:
<DOCTYPE html>
<html>
<head>
<?php
include("Mobile_Detect.php");
$detect = new Mobile_Detect();
?>
<?php if($detect->isiPad()) {
echo '<link rel="stylesheet" href="/style/iPad.css" type="text/css">';
}
else
{
echo '<meta charset="UTF-8">
<link rel="stylesheet" href="/style.css" type="text/css">;
if (strpos($_SERVER['HTTP_USER_AGENT'], 'Chrome') !== false)
{
echo '<link rel="stylesheet" href="../style/splash-webkit.css" type="text/css">';
}
//and so on for other browsers
[etc]'
}
Run Code Online (Sandbox Code Playgroud)
这里出现的明显问题是's 之间的冲突.正如我希望的那样,echounder else,而不是在我的<style>标签的末尾结束,首先'出现在代码中,因为它是在第一个USER_AGENT声明中.我该如何绕过这个问题?
控制器代码:
def create
if current_user.id != params[:friend_id]
@return = { :curr_user_id => current_user.id, :params_id => params[:friend_id], :debug => 1 }
else
@return = { :curr_user_id => current_user.id, :params_id => params[:friend_id], :debug => 2 }
end
render :json => ActiveSupport::JSON.encode( @return )
end
Run Code Online (Sandbox Code Playgroud)
所以current_user.id是1并且params[:friend_id]通过ajax调用传递,它的值也是1
问题是它在这种情况下应该返回false时总是返回true ...是否有任何与被解析为字符串而不是整数的数字1有关?
对不起,如果这是一个愚蠢的问题,但我完全是新的,只是尝试我的手.我的代码卡住....在此之后,程序结束,无论是选择1还是2.我知道它的一些简单的东西我不知道......任何输入都值得赞赏 我复制并粘贴了我认为问题所在的部分.
System.out.println("Is this information correct? Enter 1 if it is correct, and 2 to change");
Scanner inputCorrect = new Scanner(System.in);
int pick = inputCorrect.nextInt();
boolean isCorrect = false;
while (isCorrect = false){
while (!(pick == 1) && (!(pick ==2)))
System.out.println("That is not a valid entry please try again");
if (pick == 1){
isCorrect = true;
}
if (pick == 2){
System.out.println("Enter 1 to change your name, 2 to change your age or 3 to change your gender");
Scanner inputChange …Run Code Online (Sandbox Code Playgroud) 如何简化以下if语句以消除重复?
if user.name == "john" && user.age > 10 or user.name == "wendy" && user.age > 10 or user.name == "mary" && user.age > 10
Run Code Online (Sandbox Code Playgroud)
谢谢!
我的岩石剪刀代码不起作用,我假设它是因为我错误地使用了返回值.我该怎么办?
编辑,所以我存储了这样的回报
def results (x, y):
if (x == "R" or x == "rock" or x == "r" or x == "Rock" or x == "ROCK") and (y == "S" or y == "s" or y == "Scissors" or y == "SCISSORS" or y == "scissors"):
winner = 1
return winner
Run Code Online (Sandbox Code Playgroud)
但是如何在功能之外打印"胜利者"呢?
旧
player1 = input ("Player 1: Please enter either Rock, Paper or Scissors:")
player2 = input ("Player 2: Please enter either Rock, Paper or Scissors:")
def results (x, …Run Code Online (Sandbox Code Playgroud) 我正在尝试将一些代码从C翻译成另一种语言.我没有快速访问C编译器,只是发现自己与单行if语句混淆.我知道这样的陈述:
if (condition) [statement]
Run Code Online (Sandbox Code Playgroud)
和
if (condition)
[statement]
Run Code Online (Sandbox Code Playgroud)
可以在没有括号的情况下进行评估,即相当于:
if (condition) {[statement]}
Run Code Online (Sandbox Code Playgroud)
和
if (condition)
{[statement]}
Run Code Online (Sandbox Code Playgroud)
分别,但我不确定我正在处理的示例代码.它会:
if (ge.g[*l][*k].s==1) *i=1; else *i=Ne;
*j=*l;
Run Code Online (Sandbox Code Playgroud)
我觉得第二行不受if语句的影响,但是从代码的上下文来看并不是很明显.长话短说:以上相当于:
if (ge.g[*l][*k].s==1) {*i=1;} else {*i=Ne;}
*j=*l;
Run Code Online (Sandbox Code Playgroud)
要么
if (ge.g[*l][*k].s==1) {*i=1;} else {*i=Ne;
*j=*l;}
Run Code Online (Sandbox Code Playgroud)
?
conditional ×10
php ×4
if-statement ×2
return ×2
ruby ×2
boolean ×1
c ×1
c# ×1
class ×1
controller ×1
function ×1
html ×1
java ×1
nested ×1
php-ini ×1
python ×1
syntax ×1
user-agent ×1