【问题标题】:How return string from protected function php?如何从受保护的函数php返回字符串?
【发布时间】:2018-10-17 12:20:04
【问题描述】:

我想 将索引文件中的字符串变量和变量操作传递给函数,我希望公共函数将这些变量传递给受保护的函数 根据动作提取编码的受保护函数 并将结果返回到公共函数,然后返回到索引文件 我想做这样的事情 但有些东西仍然没有消失。 有人可以帮我吗?请

index.php

$um = new Code;
if($um->Code_x('xxxstringxxx', 'D')) {
echo$_SESSION['output'];
} else {
echo'something wrong';
}
echo $output->Code_x;

代码.class.php

class Code
{   
    protected $stringx;
    protected $action;

    public function Code_x($STRINGX, $ACTION) 
    { 
        $this->stringx = $STRINGX;
        $this->action = $ACTION; 
        self::Hash_1($STRINGX, $ACTION);    
    }

    protected function Hash_1( $stringx, $action ) 
    {
        $secret_key = 
            'xxxstring_secret_keyxxx'
        ;
        $secret_iv = 
            'xxxstring_secret_ivxxx'
        ;
        $output = false;
        $encrypt_method = "AES-256-CBC";
        $key = hash( 'sha512', $secret_key );
        $iv = substr( hash( 'sha512', $secret_iv ), 64, 16 );
        if( $action == 'E' ) {
            $output = base64_encode( openssl_encrypt( $stringx, $encrypt_method, $key, 0, $iv ) );
            return $output;
        }
        else if( $action == 'D' ){
            $output = openssl_decrypt( base64_decode( $stringx ), $encrypt_method, $key, 0, $iv );
            return $output;
        }


    }
}

谁能帮我解决这个问题?请

【问题讨论】:

  • 你的班级是code还是code_x?您的示例显示它名为 Code,但您实例化了 Code_x。如果你有一个与类同名的方法,它将被用作构造函数。
  • 类是Code,公共函数是Code_x
  • 嗯,echo $output->Code_x 是一种访问属性的方式,而不是一种方法。
  • 和............
  • 现在一切正常我没有意识到即使括号之间的空格无论如何都会产生“return false”谢谢

标签: php function class hash protected


【解决方案1】:

改变...

self::Hash_1($STRINGX, $ACTION);

到这里……

return $this->Hash_1($STRINGX, $ACTION);

您可能还想将$output->Code_x 更改为$um->Code_x,因为您没有在代码示例的任何地方定义$output

【讨论】:

  • 现在一切正常我没有意识到即使括号之间的空格无论如何都会产生“return false”谢谢
  • 并且有一些方法可以使这部分函数成为公共私有或受保护的,公共函数 Code_x($STRINGX, $ACTION) 到受保护的函数 Code_x($STRINGX, $ACTION)
【解决方案2】:

现在一切正常 我什至没有意识到 括号之间的空格无论如何都会产生“return false”谢谢大家 德文郡,Coffee'd Up 黑客,蓝色

【讨论】:

    【解决方案3】:

    并且有一些方法可以使这部分功能从公共变为私有或受保护, public function Code_x($STRINGX, $ACTION)protected function Code_x($STRINGX, $ACTION)

    【讨论】:

      猜你喜欢
      • 2017-11-24
      • 2022-10-14
      • 1970-01-01
      • 1970-01-01
      • 2010-12-23
      • 2016-11-17
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多