SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Addict lmasi02's Avatar
    Join Date
    Aug 2004
    Location
    Zambia
    Posts
    257
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Undefined Variable even when define

    Hi
    I ve to php code.

    the SMS_class.php and the SMS_obj.php as follows respctively
    PHP Code:
    <?php

    #
    #SMS class
    # by Lottie

    class SendSms{
            
    //memmbers
            
    private $to;
            private 
    $from;
            private 
    $body;

            
    //methods

            
    public function set_to($to){
                    
    $this->to=$to;
            }

            public function 
    set_from($from){
                    
    $this->from=$from;
            }

            public function 
    set_body($body){
                    
    $this->body=$body;
            }


            
    //Gets

            
    public function get_to(){
                    return 
    $this->to;
            }

            public function 
    get_from(){
                    return 
    $this->from;
            }


            public function 
    get_body(){
                    return 
    $this->body;
            }

            public function 
    send_sms($to$body){

                    
    $this->set_to($to);
                    
    $my_to =$this->get_to();
                    
    $this->set_from("111");
                    
    $my_from =$this->get_from();
                    
    $this->set_body($body);
                    
    $my_body $this->get_body();

                    
    $cmd="perl /var/www/html/corporate/SMS/send_sms.pl"$my_to." '".$my_body."'";
                    
    exec($cmd);
            }
    }
    ?>
    and
    PHP Code:
    <?php

    include('SMS_class.php');
    include(
    '../config/config.inc.php');
    $my_sms=new SendSms();

    function 
    notify($to_priv,$body){
            
    //Initialise receivers

            
    echo $receivers "SELECT phone FROM users WHERE privilege='".$to_priv."'";
            
    $result mysql_fetch_array(mysql_query($receivers)) or die(mysql_error());

            
    //Now send to all
            
    if($result){
                do{
                    echo 
    $num='260'.$result['phone'];
                    
    $str $my_sms->send_sms($num$body);
                    
    //exec($str);
                    //print notification
                
    }
                while(
    $result=mysql_fetch_array($receivers));
            }
            else echo 
    "Error!";
    }
    notify('billing','testing');
    ?>
    When i run the SMS_obj.php, I get the error
    Notice: Undefined variable: my_sms in /var/www/html/corporate/SMS/SMS_obj.php on line 17
    PHP Fatal error: Call to a member function send_sms() on a non-object in /var/www/html/corporate/SMS/SMS_obj.php on line 17
    Cant feagure where the problem is because the my_sms is define
    Power of Knowledge

  2. #2
    SitePoint Enthusiast stef686's Avatar
    Join Date
    Aug 2005
    Posts
    86
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It would be because $my_sms is declared outside the function in SMS_obj.php, so when you try and use it on line 17 it errors. You could pass it through as a parameter or use "global $my_sms" at the start of your function to solve it


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •