出于某种原因,我在设置会话变量时遇到问题,并使用if / else查看该值是否等于特定的值。这是相关代码:
function ask_name(){
return "What is your name?\n\n";
$_SESSION['status'] = "name";
}
if (!isset($_SESSION["name"])||!isset($_SESSION['status'])) {
$message = ask_name();
}
elseif ($_SESSION["status"]==="name"){
$message = hello_name();
}
else{
$message = respond_to_answer();
}
我知道$_SESSION["name"]
肯定是设定的,但我无法让if/elseif/else
转移到elseif
,因为它没有$_SESSION['status']
没有设置。
我在这里缺少什么?
答案 0 :(得分:1)
return
$_SESSION['status'] = "name";
退出当前函数并返回被调用者,这意味着您的function ask_name(){
$_SESSION['status'] = "name";
return "What is your name?\n\n";
}
代码永远不会运行,切换它:
def __extractRepeats(self, repeatClass):
process = subprocess.Popen(["./repeats1/repeats11", "-i", "-r"+repeatClass, "-n2", "-psol"],stdout=subprocess.PIPE, stdin=subprocess.PIPE, stderr=subprocess.STDOUT)
process.stdin.write(' '.join(map(str,self.__concatenatedDAG)))
text_file = ''
while process.poll() is None:
output = process.communicate()[0].rstrip()
text_file += output
process.wait()
repeats=[]
firstLine = False
for line in text_file.splitlines():
if firstLine == False:
firstLine = True
continue
repeats.append(line.rstrip('\n'))
return repeats