How do I fix my php code?

0

Hello everyone I have a question, this is my code that I made but it marks me an error I leave my code:

<?php 

$web_user = 'admin';

$web_pass = 'admin';


$lyric_ip = '192.168.1.202';


$api_user = 'lyric_api';


$api_pass = 'lyric_api';

$api_version = '0.08';


$url = "http://" + $web_user + ":" + $web_pass + "@" + $lyric_ip + "/cgi-bin/exec";

class Mensaje {

public $estado = -1;
public $contenido = "";
public $destino = "";
public $message_id = -1;

function __construct($destino, $contenido){

     $this->estado=0;
    $this->contenido=$contenido;
    $this->destino=$destino;


function queue($url, $api_user, $api_pass, $api_version){

          $info = array(
  'cmd'=> 'api_queue_sms',
  'username'=> $api_user,
  'password'=> $api_pass,
  'content'=> $this->contenido,
  'destination'=> $this->destino,
  'api_version'=> $api_version
     );
    $args = urlencode(json_encode($info));
     echo $args;

        $res = file_get_contents($url + '?' + $args).read();

        $obj = json_decode($res);

        if ($obj['success']){
        $mensajes[$i]->$estado = 0;
        $this->message_id = $obj['message_id'];
        echo 'Mensaje insertado exitosamente. Ticket: ' + str($obj['message_id']);
        return 1;

        }else{
        $mensajes[$i]->$estado = -1;
        echo 'Error al insertar mensaje. Codigo de error: ' + $obj['error_code'];
        return -1;         
       }
    }

  }

 }

$gestor = fopen("archivo.csv", "r");


$datos = fgetcsv($gestor, 0, ";");
$mensajes = range(0,100);

$numero = count($datos);

for ($c=0; $c < $numero; $c++) {
    $objmsjs = new Mensaje($datos[0], $datos[1]);

      $mensajes= (array) $objmsjs;
      $mensajes[$i]->queue($url, $api_user, $api_pass, $api_version);
      $i = $i + 1; 
    }
  

error says _: Fatal error: Call to a member function queue () on null in C: \ AppServ \ www \ test_msj_php.php on line 86

And it's part:

for ($c=0; $c < $numero; $c++) {
    $objmsjs = new Mensaje($datos[0], $datos[1]);

      $mensajes= (array) $objmsjs;
      $mensajes[$i]->queue($url, $api_user, $api_pass, $api_version);
      $i = $i + 1; 
    }
    
asked by ingswsm 04.04.2017 в 00:01
source

2 answers

0
for ($c=0; $c < $numero; $c++) {
    $objmsjs = new Mensaje($datos[0], $datos[1]);

    $objmsjs->queue($url, $api_user, $api_pass, $api_version);
    $i = $i + 1; 
}

a class can not be an array, so it calls the object directly and then the function

    
answered by 04.04.2017 в 00:29
0

The class constructor is missing the closing key } and there is a key left at the end of the function queue .

    
answered by 05.05.2017 в 18:09