Wednesday, 15 January 2014

PHP: Function in class returns nothing, but returns value outside of class -



PHP: Function in class returns nothing, but returns value outside of class -

this script

<?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') $td2) { $links2[] = $td2->find('td',5)->plaintext; } $adsldown = $links2[3]; $adsldown = preg_replace('/[^0-9,]|,[0-9]*$/','',$adsldown); homecoming $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') $td2) { $links3[] = $td2->find('td',5)->plaintext; } $adsldown2 = $links3[3]; $adsldown2 = preg_replace('/[^0-9,]|,[0-9]*$/','',$adsldown2); echo $adsldown2; ?>

when seek query function within class, doesn't homecoming eg. $adsldown empty, when utilize same code outside class, echos $adsldown2.

you forgot assign results of method phone call $adsldown:

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

php

No comments:

Post a Comment