Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/14.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 使用变量from";“公共静态功能”;另一种说法是;“公共静态功能”;_Php - Fatal编程技术网

Php 使用变量from";“公共静态功能”;另一种说法是;“公共静态功能”;

Php 使用变量from";“公共静态功能”;另一种说法是;“公共静态功能”;,php,Php,我知道这个问题被问了一百次,有一百种不同的方式。但我就是不能让这个特别的工作。我真的很困惑 这是我脚本的开始: <?php class API { protected static $message, $data, $status, $session, $token, $dbo, $app; const FAIL = 0; const SUCCESS = 1; const INCOMPLETE_ARGS = 2; const GROUP_ALL

我知道这个问题被问了一百次,有一百种不同的方式。但我就是不能让这个特别的工作。我真的很困惑

这是我脚本的开始:

<?php

class API {

    protected static $message, $data, $status, $session, $token, $dbo, $app;

    const FAIL = 0;
    const SUCCESS = 1;
    const INCOMPLETE_ARGS = 2;
    const GROUP_ALLOW = array(5);

    public static function Init() {
        global $app;
        self::$status = false;
        self::$message = "Invalid request.";
        self::$data = "";
    }

    public static function Render() {
        echo preg_replace("/\\\\u([0-9abcdef]{4})/", "&#x$1;", json_encode(array(
            "status" => self::$status,
            "message" => self::$message,
            "data" => self::$data))
        );
    }
在这两者之间有更多的代码和函数

再进一步,还有另一个功能:

      public static function Login() {
      $email = (isset($_REQUEST['email'])) ? $_REQUEST['email'] : "";
                $password = (isset($_REQUEST['password'])) ? $_REQUEST['password'] : "";

                require_once ("../app/Mage.php");
                umask(0);
                ob_start();
                session_start();
                Mage::app('default');
                Mage::getSingleton("core/session", array("name" => "frontend"));
                $b2bwebsiteid = Mage::getStoreConfig('base/general/b2bwebsite');
                //$websiteId            = Mage::app()->getWebsite()->getId();
                //$store                = Mage::app()->getStore();

                $customer = Mage::getModel("customer/customer");
                $customer->website_id = $b2bwebsiteid;
                $customer->loadByEmail($email);
                $countryCodeBE = $customer->getDefaultBillingAddress()->getCountry();
                $countrybe = Mage::getModel('directory/country')->loadByCode($countryCodeBE);
                $countryid = $countrybe->getCountryId();
    .....
    .....
public static function ProductInfoNew() {
现在我想要的是,从ProductInfoNew函数中的第一个函数加载变量$countryid,这样我就可以执行以下操作:

if ($countryid == "BE") {
                $groupid = 6;
            }
            else {
                $groupid = 4;
            }
但输出似乎总是为NULL或空

我尝试将$countryid变量设置为全局、静态,尝试使用self::加载变量,我尝试了很多方法,但都无法使其工作

有人知道这样做的正确方法吗?
非常感谢。

$countryid
应该是您正在使用的类中的一个字段

class API {

    private static $country_id;

    public static function ProductInfoNew() {
        if (self::$country_id == "BE") {
            $groupid = 6;
        } else {
            $groupid = 4;
        }
    }
}

在你的问题中,你说“Then there is this function:”的部分,你在下面放了一堆代码。。功能在哪里?我只是看到一堆代码。啊,正确,对不起。它现在要么将变量作为参数传递给函数,要么在API类中使其成为静态的。请记住使用正确的语法。它应该类似于
class\u name::$var\u name
。它仍然显示输出空值。。应该是$country\u id还是$countryid?顺便说一句,两种方法都试过了,但都没有成功。@ErjenRijnders请做一个var_dump($country_id)并告诉我们它说了什么。此外,请确保在引用其值之前的某个时间点对其进行设置。