Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 862181
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T09:06:00+00:00 2026-05-15T09:06:00+00:00

i’m new related to creating php class’s and objects… I’m trying to make a

  • 0

i’m new related to creating php class’s and objects…
I’m trying to make a class to comunicate with our company api.

When i’m calling a function to a variable, php hangs with error:

Parse error: syntax error, unexpected T_VARIABLE in /var/www/(...)/microdualapi.class.php  on line 168

Can anybody give me a light? 🙂
The code is above:

if(!class_exists("Microdual")) class Microdual{

    // No caso de a sessão não estar iniciada, iniciar aqui a sessão
    //session_start();

    ################
    ################
    ################
    ################ Iniciar funcoes privadas ################

    private function Extra_LoadSession($varname,$otherwise){
        //return (!empty($_SESSION[$this->Session_Prefix . $varname])) ? $_SESSION[$this->Session_Prefix . $varname] : $otherwise;
        return "OLA";
    }
    private function Extra_SaveSession($varname,$value){
        $_SESSION[$Session_Prefix.$varname] = $value;
        return true;
    }
    /**
    * $this->Extra_PostRequest()    "Comunicar comandos com os servidores Microdual (enviar e receber)"
    *
    * @author   Jonas John
    * @link     "http://www.jonasjohn.de/snippets/php/post-request.htm"
    *
    * @param    url string  
    * @param    referer string  
    * @param    data    array   
    *
    * @return   array($header,content)
    */
    private function Extra_PostRequest($url, $referer, $_data) {

        // convert variables array to string:
        $data = array();    
        while(list($n,$v) = each($_data)){
            $data[] = "$n=$v";
        }    
        $data = implode('&', $data);
        // format --> test1=a&test2=b etc.

        // parse the given URL
        $url = parse_url($url);
        if ($url['scheme'] != 'http') { 
            die('Only HTTP request are supported !');
        }

        // extract host and path:
        $host = $url['host'];
        $path = $url['path'];

        // open a socket connection on port 80
        $fp = fsockopen($host, 80);

        // send the request headers:
        fputs($fp, "POST $path HTTP/1.1\r\n");
        fputs($fp, "Host: $host\r\n");
        fputs($fp, "Referer: $referer\r\n");
        fputs($fp, "Content-type: application/x-www-form-urlencoded\r\n");
        fputs($fp, "Content-length: ". strlen($data) ."\r\n");
        fputs($fp, "Connection: close\r\n\r\n");
        fputs($fp, $data);

        $result = ''; 
        while(!feof($fp)) {
            // receive the results of the request
            $result .= fgets($fp, 128);
        }

        // close the socket connection:
        fclose($fp);

        // split the result header from the content
        $result = explode("\r\n\r\n", $result, 2);

        $header = isset($result[0]) ? $result[0] : '';
        $content = isset($result[1]) ? $result[1] : '';

        // return as array:
        return array($header, $content);
    }
    /**
    * $this->API_Comunicate()   "Comunicar comandos com os servidores Microdual (enviar e receber)"
    *
    * @param    data    array   "Colocar as variaveis que deseja passar à plataforma (Ver Lista completa de variaveis no Inicio)"
    *
    * @return   array or void (false)
    */
    private function API_Comunicate($data){
        list($header, $content) = Extra_PostRequest($Geral_URLAPI, "http://".$_SERVER["SERVER_NAME"]."/" , $data);
        if(!empty($content)){
            return json_decode($content);
        }else{
            return false;
        }
    }


    ################
    ################
    ################
    ################ Iniciar funcoes Públicas ################

    /**
    * $this->IsLogged() "Verificar se está autenticado no servidor (primeiro localmente, e depois liga ao servidor)"
    *
    * @return   void
    */
    public function IsLogged(){
        if($logged) return true;
        $logged = Extra_LoadSession("Login_Logged",false);
        if($logged){
            return true;
        }else{
            // Conectar ao servidor
            $dados = API_Comunicate(array());
            if($dados!==false){
                if(!empty($dados['auth']['logged'])){
                    return $dados['auth']['logged'];
                }else{
                    return false;
                }
            }else{
                return false;
            }
        }
    }

    /**
    * $this->Login()    "Executar o Login nos servidores Microdual"
    *
    * @param    username    string  "Colocar aqui o nome de utilizador da sua conta em www.microdual.com"
    * @param    password    string  "Colocar aqui a password da sua conta em www.microdual.com"
    *
    * @return   void
    */
    public function Login($username,$password){
        if(empty($username) || empty($password)) return false;
        if($this->IsLogged()) return true;

    }


    ################
    ################
    ################
    ################ Iniciar variaveis da class (is buscar valor à sessão no caso de existir) ################

    private $Session_Prefix = "PREFFIX_";
    private $Geral_URLAPI = "http://www.MYSITE.com/MYapi";
    private $Login_Logged = $this->Extra_LoadSession("Login_Logged",false);


};

thanks in advance!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T09:06:00+00:00Added an answer on May 15, 2026 at 9:06 am

    You say this is the offending line:

    private $Login_Logged = $this->Extra_LoadSession("Login_Logged",false); 
    

    You can’t pre-populate a class variable by calling a method: A class definition is static. No $this exists at the time of the class definition, and no code can be executed.

    You’ll have to set that variable in your constructor:

    private $Login_Logged;
    
    function __construct()
     {
       $this->Login_Logged = $this->Extra_LoadSession("Login_Logged",false); 
    
     }
    

    PHP Manual on constructors and destructors

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I'm trying to create an if statement in PHP that prevents a single post
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
I would like to count the length of a string with PHP. The string
I am trying to understand how to use SyndicationItem to display feed which is
this is what i have right now Drawing an RSS feed into the php,
I want use html5's new tag to play a wav file (currently only supported
I am doing a simple coin flipping experiment for class that involves flipping a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.