Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/261.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 在另一个类中调用函数不需要';行不通_Php - Fatal编程技术网

Php 在另一个类中调用函数不需要';行不通

Php 在另一个类中调用函数不需要';行不通,php,Php,这是一个快速的noob问题。我试图调用另一个类中的函数,但它不起作用。提前谢谢 ** main.php ** require_once("../push/push.php"); new APNS_Push($config); start(); ** push.php ** class APNS_Push { private $fp = NULL; private $server; private $certificate; private $passphrase; function _

这是一个快速的noob问题。我试图调用另一个类中的函数,但它不起作用。提前谢谢

** main.php **
require_once("../push/push.php"); 
new APNS_Push($config);
start();


** push.php **

class APNS_Push
{
private $fp = NULL;
private $server;
private $certificate;
private $passphrase;

function __construct($config)
{
    $this->server = $config['server'];
    $this->certificate = $config['certificate'];
    $this->passphrase = $config['passphrase'];

    // Create a connection to the database.
    $this->pdo = new PDO(
        'mysql:host=' . $config['db']['host'] . ';dbname=' . $config['db']['dbname'], 
        $config['db']['username'], 
        $config['db']['password'],
        array());


    // If there is an error executing database queries, we want PDO to
    // throw an exception.
    $this->pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

    // We want the database to handle all strings as UTF-8.
    $this->pdo->query('SET NAMES utf8');
}

// This is the main loop for this script. It polls the database for new
// messages, sends them to APNS, sleeps for a few seconds, and repeats this
// forever (or until a fatal error occurs and the script exits).
function start()
{
    //writeToLog('Connecting to ' . $this->server);

    if (!$this->connectToAPNS())
        exit;


        // Do at most 20 messages at a time. Note: we send each message in
        // a separate packet to APNS. It would be more efficient if we 
        // combined several messages into one packet, but this script isn't
        // smart enough to do that. ;-)

        $stmt = $this->pdo->prepare('SELECT * FROM push_queue WHERE time_sent IS NULL LIMIT 25');
        $stmt->execute();
        $messages = $stmt->fetchAll(PDO::FETCH_OBJ);

        $deletedIds = array();

        foreach ($messages as $message)
        {
            echo 's'; 
            if ($this->sendNotification($message->message_id, $message->device_token, $message->payload))
            {
                //$stmt = $this->pdo->prepare('UPDATE push_queue SET time_sent = NOW() WHERE message_id = ?');

                $name = $message->name; 
                echo $name; 
                $value = '1'; 
                //$this->pdo->query('UPDATE users SET needsUpdate = '$value' WHERE username='$name'');

                //$stmt->execute(array($message->message_id));

                 $deletedIds[] = $message->message_id;

                //$stmt = $this->pdo->prepare('DELETE FROM push_queue WHERE message_id = ?');
                //$stmt->execute(array($message->message_id));

            }
            else  // failed to deliver
            {
                $this->reconnectToAPNS();
            }
        }

        //Delete the chunk of messages.
        $this->pdo->query('DELETE FROM push_queue WHERE message_id IN ('.implode(',', $deletedIds).')');


        //echo 'success'; 

        unset($messages);           

}

我看到一个丢失的
}
。我在课程结束时补充说,下面的内容很好

$myPush = new APNS_Push($config);
$myPush->start();

可能会告诉我们哪个函数给了您错误。您没有将$this->pdo设置为类属性。你需要一个
private$pdo