简体   繁体   中英

Fatal Error : call to undefined function , PHP

I am working with php, and trying to call a function within a block of code, but I do not know why it causing the error that Uncaught Error: Call to undefined function GetUserIDFromUsername() , while it is defined later then.

The PHP Code

  if(isset($_GET["updateRow"])){ $_fbURL = $_GET["ajaxified"]; if(!empty($_fbURL)){ $url = $_fbURL; $urlParts = explode("facebook.com/", $url); $username = GetUserIDFromUsername($urlParts[1]); function GetUserIDFromUsername($username) { // For some reason, changing the user agent does expose the user's UID $options = array('http' => array('user_agent' => 'some_obscure_browser')); $context = stream_context_create($options); $fbsite = file_get_contents('https://www.facebook.com/' . $username, false, $context); // ID is exposed in some piece of JS code, so we'll just extract it $fbIDPattern = '/\\"entity_id\\":\\"(\\d+)\\"/'; if (!preg_match($fbIDPattern, $fbsite, $matches)) { throw new Exception('Unofficial API is broken or user not found'); } return $matches[1]; } echo "My Id is : "." ".$username; } } 

Declare your method GetUserIDFromUsername($params) before calling it. You can move the method to the top of the caller.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM