簡體   English   中英

如何從 class 內部調用在 class 外部定義的 function

[英]How can I call a function that is defined outside of a class from inside a class

所以我並沒有真正嘗試太多,因為我是 OOP 的新手,我所嘗試的只是制作一個 function 來設置動作的進度條。 當我從 class 內部調用它時,它說 function 不存在。 我怎樣才能解決這個問題? 謝謝!

如果我不在 class 中調用 function ,則進度條可以正常工作。


function progresSet($parama, $paramb) {
code to set prgress;

}

class register {

    function a(dasdsadasd) {
    
        progressSet('50', 'red');

    }

}

錯誤

Fatal error: Uncaught Error: Call to undefined function progressSet() in /home/xkhckrzf/xenonmc/controller/controllers/register/main.php:280 Stack trace: #0 /home/xkhckrzf/xenonmc/controller/controllers/register/main.php(382): registerCntlr->main() #1 {main} thrown in /home/xkhckrzf/xenonmc/controller/controllers/register/main.php on line 280

你有一些錯別字,但你可以,看看:

<?php

function progressSet($parama, $paramb) {
    echo $parama . " - " . $paramb;
}

class register {
    function classFunction($param1, $param2) {
        progressSet($param1, $param2);
    }
}


$register = new register();
$register->classFunction('50', 'red')
?>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM