[英]php Warning & Strict Standards
I am using $_SESSION[''];
我正在使用
$_SESSION[''];
to get values from a user after they have logged in. This data is coming from the users
table. 以便在用户登录后从用户那里获取值。此数据来自
users
表。
I am then trying to 然后我试图
`SELECT *` `FROM roster`
by doing a query and assigning a var for each value when the users API=$API
通过查询并在用户
API=$API
时为每个值分配一个var
I can do so by using the following: 我可以使用以下方法做到这一点:
error_reporting(E_ALL);
include ('database_connection.php');
$API = $_SESSION['API'];
if ($API !== false) {
$roster_query = "SELECT * FROM roster WHERE API='$API'";
$result = mysqli_fetch_array(mysqli_query($dbc, $roster_query));
/* ROSTERS TABLE */
$StreetName = $result['streetname'];
$HouseNum = $result['housenumber'];
$City = $result['city'];
$State = $result['state'];
$Zipcode = $result['zipcode'];
/* SESSION */
$FirstName = $_SESSION['firstname'];
$LastName = $_SESSION['lastname'];
$Email = $_SESSION['email'];
/* this->$vars - Specific for this form */
$ExecutionDate = date("Y:M:D");
$DOCSIGNEDBYIP = $_SERVER['REMOTE_ADDR'];
}
However, I get the following errors when I do. 但是,这样做时出现以下错误。 If I remove the above code no errors, etc.
如果我删除上面的代码没有错误,等等。
Now this isnt 'breaking' my code, but I do not want to sweep this under the rug and resolve later. 现在,这并没有“破坏”我的代码,但是我不想扫一扫而后解决。
Can someone identify where I am going wrong ? 有人可以确定我要去哪里吗?
Warning: Creating default object from empty value in /home/.../public_html/.../.../.../db.php on line 48
警告:从第48行的/home/.../public_html/.../.../.../db.php中的空值创建默认对象
line 48: $return->$i = $row;
第48行:
$return->$i = $row;
if(!$return_array) {
while($row = mysql_fetch_object($sql_query)) {
$return->$i = $row;
$i++;
}
Strict Standards: Non-static method Access::is_logged() should not be called statically, assuming $this from incompatible context in /home/.../public_html/.../.../.../APP.php on line 64
严格标准:假设$ this来自/home/.../public_html/.../.../.../APP.php中的不兼容上下文,则不应静态调用非静态方法Access :: is_logged()在第64行
pinAPP
line 64: return Access::is_logged();
pinAPP
第64行: return Access::is_logged();
public function is_logged()
{
return Access::is_logged();
}
is_logged(); is_logged();
<?php
require_once(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'init.php');
class pinAPP {
public function is_logged() {
return Access::is_logged();
}
}
Access 访问
<?php
class Access {
private static $auth = false;
final public function is_logged( $require_admin_access = false ) {
if ( ! isset($_SESSION[LOGINSESSION]) )
return false;
self::$auth = true;
if ( $require_admin_access ) {
$u = new User();
if ( ! $u->is_admin() )
new Redirect(DEFAULT_RETURN_URL);
}
return self::$auth;
}
}
Try these, see if they work: 试试看,看看它们是否有效:
// Set an empty object for $return first
$return = new stdClass();
if( ! $return_array ) {
$i = 0;
while ( $row = mysql_fetch_object($sql_query) ) {
$return->$i = $row;
$i++;
}
I think the other is saying you should have is_logged()
as a static
function: 我认为另一个是说您应该将
is_logged()
作为static
函数:
class Access
{
static function is_logged()
{
// code here
}
}
$row
use !empty($row)
( just Warning ) $row
使用!empty($row)
( 仅警告 ) static functon is_logged()
static functon is_logged()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.