PHP:类中的函数不返回任何内容,但返回类之外的值

时间:2014-06-26 13:02:09

标签: php

这是我的剧本

<?php
require_once("simple_html_dom.php");

class adsl{

function up($lat,$lon){

$links2 = array();
$html = file_get_html('http://www.tpg.com.au/maps/getclosest.php?latitude='.$lat.'&longitude='.$lon.'&exch=GUESS');
foreach($html->find('tr') as $td2) {
 $links2[] = $td2->find('td',5)->plaintext;
}
$adsldown = $links2[3];
$adsldown = preg_replace('/[^0-9,]|,[0-9]*$/','',$adsldown); 
return $adsldown;
}
}
$test = new adsl();

$test->up('-37.8571449','144.8813738');

echo $adsldown;

$lat = '-37.8571449';
$lon = '144.8813738';
$links3 = array();
$html = file_get_html('http://www.tpg.com.au/maps/getclosest.php?latitude='.$lat.'&longitude='.$lon.'&exch=GUESS');
foreach($html->find('tr') as $td2) {
 $links3[] = $td2->find('td',5)->plaintext;
}
$adsldown2 = $links3[3];
$adsldown2 = preg_replace('/[^0-9,]|,[0-9]*$/','',$adsldown2); 
echo $adsldown2;

?>

当我尝试查询类中的函数时,它不会返回任何内容,例如。 $ adsldown为空,但当我在课外使用相同的代码时,它会回显$ adsldown2。

1 个答案:

答案 0 :(得分:1)

您忘记将方法调用的结果分配给$adsldown

$adsldown = $test->up('-37.8571449','144.8813738');

echo $adsldown;