Web lists-archives.com

RE: [PHP] asterisk with php





> -----Original Message-----
> From: Jigar Dhulla [mailto:jigar.tidus@xxxxxxxxx]
> Sent: Wednesday, July 22, 2015 10:26 PM
> To: hadi
> Cc: php-general@xxxxxxxxxxxxx General
> Subject: Re: [PHP] asterisk with php
> 
> On Wed, Jul 22, 2015 at 11:51 PM, hadi <almarzuki2011@xxxxxxxxxxx> wrote:
> 
> > Hi,
> >
> > I have project, Asterisk with phpagi, when I pass variable to function
> > I get error "Notice: Undefined variable: pin".
> >
> > Here is my code
> >
> >
> >
> > #!/usr/local/bin/php -q
> > <?php
> >
> > error_reporting(E_ALL);
> > ini_set('display_errors', 1);
> >
> > require("phpagi.php");
> > require("database.php");
> >
> >
> >
> >
> >
> > $agi=new AGI();
> >
> >
> >
> > $agi->answer();
> >
> >
> > for ($x = 0; $x <= 3; $x++)
> > {
> >
> >
> >
> >
> > $result = $agi->get_data('/var/lib/asterisk/agi-bin/ivr-sound1', 3000,
> > 20);
> >
> >
> > $pass = $result['result'];
> >
> >
> > $query = $conn->prepare("SELECT COUNT(*) FROM userinfo where
> > pin=:pin"); $query->bindParam(':pin', $pass);
> >
> > $query->execute();
> >
> > $num_rows = $query->fetchColumn();
> >
> > if($num_rows == 1)
> >
> >
> >
> >
> > {
> > $agi->text2wav("thankyou");
> >
> >
> >
> > $agi->text2wav("please enter number to dial for more information press
> > zero");
> >
> >
> > $num = $agi->exec("Read","pin,,4,3,120");
> >
> > $temp = $agi->get_variable("pin");
> >
> > $pin = trim($temp["data"]);
> >
> > global $pin;
> >
> > break;
> >
> > }
> >
> >
> > if ($x ==  3)
> >
> > {
> > $agi->hangup();
> >
> > }
> >
> > }
> >
> > ​
> > ​
> > ​
> > dialout($pin);
> >
> >
> > function
> > ​
> > dialout($pin)
> >
> > {
> >
> >
> >
> > $agi=new AGI();
> >
> > $agi->exec_dial("SIP/$pin");
> >
> > $Answeredtime = $agi->get_variable ("ANSWEREDTIME");
> >
> > $agi->hangup ();
> >
> >
> > }
> >
> >
> >
> >
> > ?>
> >
> >
> >
> >
> > --
> > PHP General Mailing List (http://www.php.net/) To unsubscribe, visit:
> > http://www.php.net/unsub.php
> >
> >
> ​Hi,
> 
> That "Notice" means you are trying to use/access that variable even though it
> is not yet defined/set.
> 
> Looking at your code, if I am not wrong *$pin* is defined only when
> *$num_rows == 1, *right ? Hence, when ​ ​​ ​​
> ​​*​dialout($pin) *is called *$pin *will remain undefined in other cases, so the
> notice(this is just one of the possibility).
> 
> So the best solution is to use *isset($pin) *where you think *$pin *can be
> not defined/set.
> 
> 
> *if(isset($pin) && !empty($pin)){*
> 
> *  ​dialout($pin);*
> *}*
> 
> Also in production/live environment, don't forget to suppress the notice
> *error_reporting(E_ALL & ~E_NOTICE & ~E_WARNING & ~E_STRICT &
> ~E_DEPRECATED); *you might not want your users to see those notice or
> warning. Avoid suppressing such things in development environment.


> Looking at your code, if I am not wrong *$pin* is defined only when
> *$num_rows == 1, *right ?

Yes your right..

When I do "var_dump($pin)" at the beginning of the function it show the variable correct.
But when I do "var_dump($pin)" after  "$agi=new AGI();" it show nothing.

I think  "$agi=new AGI();" it wipe out my "$pin" variable....






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