php脚本只允许调用一个带有参数的函数
我在中编写了一个包含2个函数的php类,但当我调用不同脚本中的函数时,它只允许运行2个函数中的1个 这是包含函数的脚本php脚本只允许调用一个带有参数的函数,php,function,Php,Function,我在中编写了一个包含2个函数的php类,但当我调用不同脚本中的函数时,它只允许运行2个函数中的1个 这是包含函数的脚本 <?php define('RDFAPI_INCLUDE_DIR', 'rdfapi-php/api/'); require_once('SimpleRdfParser.php'); class retrieve{ public $p; public $uri; public $rdf; function retrieve(){ $th
<?php
define('RDFAPI_INCLUDE_DIR', 'rdfapi-php/api/');
require_once('SimpleRdfParser.php');
class retrieve{
public $p;
public $uri;
public $rdf;
function retrieve(){
$this->p = new SimpleRdfParser();
$this->uri = 'rdfs/crime.owl';
$this->rdf = @file($this->uri);
}
function getName(){
return "heyyy";
}
public function getL1Comment($type){
/*
this function gets the comments that are to do with the main type of crime i.e. Sexual Offences
*/
if (is_array($this->rdf)) {
$this->rdf = join('', $this->rdf);
if (is_array($data = $this->p->string2triples($this->rdf, $this->uri))) {
$val = $data["http://localhost/".$type][2][1][0];
return $val;
exit;
}
}
}
public function getChildComment($crime){
/*
this function gets the comments from the child node of the main type of crime i.e. Rape of a Female aged 16 and over,
this is a child node of Sexual Offences
*/
if (is_array($this->rdf)) {
$this->rdf = join('', $this->rdf);
if (is_array($data = $this->p->string2triples($this->rdf, $this->uri))) {
$val = $data["http://localhost/".$crime][2][1][0];
return $val;
exit;
}
}
}
}
有人知道为什么会这样吗
提前谢谢退出 您的函数中有exit,因此在转到下一个函数之前它会被转义,这就是为什么: 它们都这样做
$this->rdf=join(“”,$this->rdf)代码>
它们都是有条件的:
if (is_array($this->rdf))
因此,第一个是导致数组不再是数组。因此,第二个方法的条件将失败
试着这样做:
public function getL1Comment($type){
/*
this function gets the comments that are to do with the main type of crime i.e. Sexual Offences
*/
if (is_array($data = $this->p->string2triples(join('', $this->rdf), $this->uri))) {
$val = $data["http://localhost/".$type][2][1][0];
return $val;
}
}
这样,您就不会在方法中重新定义$this->rdf,因为在我看来,没有理由这样做。您的getL1Comment
中有exit
,这会导致执行停止;删除它,它将遍历代码的其余部分exit
语句是否从未到达?函数的执行应该在return
语句中终止,永远不会到达exit
。我删除了exit
,它仍然没有调用它谢谢你,我尝试了你的建议,它给了我一个错误,并进一步进入了我正在使用的API,所以我尝试将它放入构造函数中,效果很好。
public function getL1Comment($type){
/*
this function gets the comments that are to do with the main type of crime i.e. Sexual Offences
*/
if (is_array($data = $this->p->string2triples(join('', $this->rdf), $this->uri))) {
$val = $data["http://localhost/".$type][2][1][0];
return $val;
}
}