PHP 访问对象方法时出现问题
对于 PHP 本身来说并不是完全陌生的,但是对于使用 OOP 和 PHP 来说是陌生的。
对象实例化&调用方法存在于不同的文件中。
index.php 有这个:
<?php
require_once 'scripts/twitteroauth/oauth_index.php';
?>
oauth_index.php 有这个:
$twitter = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET, $access_token['oauth_token'], $access_token['oauth_token_secret']);
提交推文的文件,submitMessage.php 包含这个:
include 'twitteroauth/oauth_index.php';
$message = $_GET['message'];
$time = $_GET['time'];
$status = "#" . $message . $time;
$twitter->updateStatus($status);
$output = $twitter->updateStatus($status);
有测试: 表单提交成功&获取 PHP 文件。 updateStatus() 方法如果在index.php 中使用,可以正常工作。然而,当我提交表单时,它被传递给一个js函数,该函数将变量传递给submitMessage.php,然后用$twitter->之后的所有文本进行响应。它响应“updateStatus($status);$output = $twitter->updateStatus($status);”
关于我做错了什么有什么想法吗?感谢您的任何帮助。
整个sendMessage.php
<?
include 'twitteroauth/oauth_index.php';
$message = $_GET['message'];
$time = $_GET['time'];
$status = "#" . $message . $time;
$output = $twitter->updateStatus($status);
$twitterReturn = new SimpleXMLElement($output);
echo $output;
?>
Not completely new to PHP itself, but new to using OOP w/ PHP.
Object instantiation & calling method exist in different file.
index.php has this:
<?php
require_once 'scripts/twitteroauth/oauth_index.php';
?>
oauth_index.php has this:
$twitter = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET, $access_token['oauth_token'], $access_token['oauth_token_secret']);
and the file submitting the tweet, submitMessage.php contains this:
include 'twitteroauth/oauth_index.php';
$message = $_GET['message'];
$time = $_GET['time'];
$status = "#" . $message . $time;
$twitter->updateStatus($status);
$output = $twitter->updateStatus($status);
Have tested:
The form submits successfully & gets to the PHP file. The updateStatus() method works fine if it is used within index.php. However, when I submit the form, it is passed to a js function, which passes the variables to the submitMessage.php, and then responds with all the text after $twitter->. It responds "updateStatus($status);$output = $twitter->updateStatus($status);"
Any ideas as to what I'm doing wrong? Thanks for any help.
entirety of sendMessage.php
<?
include 'twitteroauth/oauth_index.php';
$message = $_GET['message'];
$time = $_GET['time'];
$status = "#" . $message . $time;
$output = $twitter->updateStatus($status);
$twitterReturn = new SimpleXMLElement($output);
echo $output;
?>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要回显
$output
;You need to echo the
$output
;