dowbwrr3590709
2011-01-04 18:21
浏览 36
已采纳

如何通过传递$ _GET参数来调用静态函数?

i have got a static function> which is called regenerateThumbnailsCron()

And I would like to execute this function by GET params, for example>

if($_GET["pass"]=="password")
self::regenerateThumbnailsCron();

But if I tryied to call this function in constructor> class AdminImages extends AdminTab ...

 public function __construct()
 {
    if($_GET["pass"]=="password")
    self::regenerateThumbnailsCron();
}

I cannot execute this function. Is any way, how to call this function before __construct to correctly execute?

Thanks very much for any advice.

EDIT>

I tried also with public function>

<?php
include 'AdminImages.php';

$images = new AdminImages();
$images->regenerateThumbnailsCron();

?>

But i got error> Fatal error: Class 'AdminTab' not found

图片转代码服务由CSDN问答提供 功能建议

我有一个静态函数&gt; 这个叫做 regenerateThumbnailsCron()

我想通过GET参数执行这个函数,例如&gt;

  if($  _GET [“pass”] ==“password”)
self :: regenerateThumbnailsCron(); 
   
 
 

但是如果我试图在构造函数中调用此函数&gt; class AdminImages扩展了AdminTab ...

  public function __construct()
 {
 if if($ _ GET [“pass”] ==“password”)
 self  :: regenerateThumbnailsCron(); 
} 
   
 
 

我无法执行此函数。 无论如何,如何在__construct之前调用此函数以正确执行?

非常感谢任何建议。

编辑&gt;

我还尝试使用公共功能&gt;

 &lt;?php 
include'AdminImages.php'; 
 
 $ images = new AdminImages(); 
 $ images-&gt; regenerateThumbnailsCron(); 
 
  ?&gt; 
   
 
 

但是我收到了错误&gt; Fatal错误:未找到类'AdminTab'

  • 写回答
  • 好问题 提建议
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • dousu8767 2011-01-04 18:25
    已采纳

    You need to do a include 'AdminTab.php'; as well, since your class extends that

    已采纳该答案
    评论
    解决 无用
    打赏 举报
  • donglu9872 2011-01-04 18:32

    Not completely sure I understand your question, are you saying that you have static class "B" which extends class "A", "A" having your regenerateThumbnailsCron() method which you want to call before anything else?

    If so then try this:

    <?php
    class A {
      private function regenerate() {
      .... do something ....
      }
    }
    
    class B extends A {
      function __construct() {
        if ($_GET["pass"] == "password") {
          parent::regenerate();
        }
      }
    
      function regenerateThunbnailsCron() {
      .... do somethinig ....
      }
    
    }
    
    $images = new B();
    $images->regenerateThumbnailsCron();
    ?>
    

    This way, your parent's "regenerate()" function would get called during the constructor. You can switch this around to be a static class if you want, which if your goal is to compartmentalise any variables and functions away from the global scope would be a better way.

    评论
    解决 无用
    打赏 举报

相关推荐 更多相似问题