-1

I'm getting the following output on my page when I go to Test.php:

    longitude = $long; 
    $this->latitude = $lat; 
} 

public function getgeo(){ 
    require_once('lib/mapbox/MapBox.php'); 
    $request = new MapBox('redacted'); 
    $request = $request->reverseGeocode($this->longitude,$this->latitude); 
    $request = explode(', ',$request[0]['place_name']); 
    if(count($request)>3){ 
        array_shift($request); 
        array_splice($request,2,1); 
    }
    $return = array($request[0],$request[2]); 
} 
} 
?>

Fatal error: Uncaught Error: Class 'ReverseGeo' not found in /var/www/html/api.redacted.com/public_html/test.php:8 Stack trace: #0 {main} thrown in /var/www/html/api.redacted.com/public_html/test.php on line 8

Test.php

<?php
require_once(__dir__ . '/classes/reversegeo.php');

$long = '-73.988909';
$lat = '40.733122';

$reversegeo = new ReverseGeo($long, $lat);
$return = $reversegeo->getgeo();

var_dump($return);

?>

classes/reversegeo.php

Class ReverseGeo{

protected $longitude;
protected $latitude;

public function __construct($long, $lat){
    $this->longitude = $long;
    $this->latitude = $lat;
}

public function getgeo(){
    require_once('lib/mapbox/MapBox.php');
    $request = new MapBox('redacted');
    $request = $request->reverseGeocode($this->longitude,$this->latitude);

    $request = explode(', ',$request[0]['place_name']);

    if(count($request)>3){
        array_shift($request);
        array_splice($request,2,1);
    }

    $return = array($request[0],$request[2]);
}
}

I've confirmed that directories are all correct, file names are correct, etc. and I'm not sure whats going on with this.

Qirel
  • 25,449
  • 7
  • 45
  • 62
Kaylined
  • 655
  • 6
  • 15

1 Answers1

2

Per our discussion in chat, as your php does not support the short opening tag you need to use the full opener. The short tag is the reason that your php source code gets sent directly to the browser and not to the php engine.

You can configure your php settings to allow the short opening tag but its not recommended for portability reasons.

<? should be changed to <?php

As a side note later versions of php no longer need the closing tag at the end of the file so that can be removed if your php supports it.

CodingInTheUK
  • 930
  • 7
  • 16