Class not returning value

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi

This is my first class and it does not work, i do a return 
$this->responseArray; with the public function getResult() method, but get 
nothing. Can someone please help me.

Thsi is how i create the object
$number = new Smsgate($cell_numbers, $message, "27823361602", "27");
$result = $number->getResult();

Here is the code:
<?php

/**
 *
 * @version 1.0
 * @copyright 2009
 */

/**
 */
class Smsgate {

    protected $number;
    protected $message;
    protected $sender_id;
    protected $tofind;
    private $result;
    /**
     * Constructor
     */
    function __construct($number = "", $message = "", $sender_id = "", 
$tofind = "")
    {

        $this->message = $message;
        $this->number = $number;
        $this->sender_id = $sender_id;
        $this->tofind = $tofind;
    }

    protected function display ($result)
    {
        return $result;
    }

    public function getResult()
    {
        return $this->processRequest();

    }
    public function numberErrors()
    {
        return $this->errorResult;
    }

    /**
     * Smsgate::checknumbers()
     *
     * @return array of correct and incorrect formatted numbers
     */
    private function processRequest()
    {
        echo "nou by numers";
        print_r($this->number);
        // check if the property is an array and add to new array for 
sending
        if (is_array($this->number)) {
            // check for starting digits
            $this->result = "";
            // loop through numbers and check for errors
            foreach ($this->number as $this->val) {

                $this->position = strpos($this->val , $this->tofind);

                // number correct
                if ($this->position === 0) {
                    echo "is integer <br/>";
                    if ($this->result != "") {
                        $this->result .= ",";
                    }
                    // create comma seperated numbers to send as bulk in 
sendSMS method
                    $this->result .= $this->val; //infobip multiple 
recipients must be seperated by comma
                    // create an array to use with responseStringExplode in 
sendSMS method
                    $this->cellarray[] = $this->val;
                    echo "Result is " . $this->result . "<br>";
                } else {
                    // numbers not in correct format
                    $this->errorResult[] = $this->val;
                }

            } //end foreach
   $this->sendSMS();

        } else {
            $this->result = "Not ok";
         return $this->result;
        }

    }

    private function sendSMS()
    {

        $this->smsUrl = 
'http://www.infobip.com/Addon/SMSService/SendSMS.aspx?user=xxxx&password=xxxx';
        $this->post_data = '&sender=' . $this->sender_id . '&SMSText=' . 
urlencode($this->message) . '&IsFlash=0&GSM=' . $this->result;
        $this->sendData = $this->sendWithCurl($this->smsUrl, 
$this->post_data);
        $this->responseStringExplode = explode("\n", $this->sendData);

     $count=0;
        foreach ($this->responseStringExplode as $this->rvalue) {
          $this->responseArray[$this->rvalue] = ($this->cellarray[$count]);
          $count = ++$count;
        }
     return $this->responseArray;
    }
 private function sendWithCurl($url, $postData) {
  if (!is_resource($this->connection_handle)) {
   // Try to create one
   if (!$this->connection_handle = curl_init()) {
    trigger_error('Could not start new CURL instance');
    $this->error = true;
    return;
   }
  }
  curl_setopt($this->connection_handle, CURLOPT_URL, $url);
  curl_setopt ($this->connection_handle, CURLOPT_POST, 1);
  $post_fields = $postData;
  curl_setopt ($this->connection_handle, CURLOPT_POSTFIELDS, $post_fields);
  curl_setopt($this->connection_handle, CURLOPT_RETURNTRANSFER, 1);
  $this->response_string = curl_exec($this->connection_handle);
  curl_close($this->connection_handle);
  return $this->response_string;
 }
}

?> 



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux