作者HuangJC (吹笛牧童)
看板PHP
標題Re: [請益] 有沒有法子把 $this pass 掉
時間Sun Jul 13 18:31:25 2008
其實無法描述清楚大概是我改不掉,或要改很久的毛病了 :P
我試著寫一個假想的程式片段來描述吧!!
demo.thtml
<?php
//do something
$this->here();
?>
我改成
demo.php
<?php
//do something
here();
?>
然後在我自己的程式裏就可以載入它,但因為 here 沒定義,我就得生給它
my.php
<?php
function here()
{
//cheat code
}
require 'demo.php';
?>
這方法其實還不錯,都已經成功了
但我其實很想寫一支程式,不必去手動改 demo.php
my_want.php
<?php
//powerful cheat env. in need,I can't do it
require 'demo.thtml';
?>
目前是這樣
剛想到一個法子
my_try.php
<?php
class Cheat
{
function here()
{
//cheat code
}
ruquire 'demo.thtml';
}
$run=new Cheat;//make it run
?>
如上,既然我把整個 demo.thtml 載入到一個 class 裏了
那麼 $this 就指到 class 內部,我也就可以騙過它了
結果我得到一個錯誤訊息 :P
syntax error, unexpected T_REQUIRE, expecting T_FUNCTION in my_try.php
譯:小子,這樣想騙過我?不可以啦,再回去改一版試試
突然之間就 抖抖 了,唉..
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 61.59.179.152
推 weiyucsie :那就放在函數裡就好了?XD 07/13 18:42
→ weiyucsie :不過如果裡面有函數的話不知道會不會炸XD 07/13 18:45
→ weiyucsie :我指的是thtml裡面如果有的話 07/13 18:45
→ HuangJC :對..有一堆問題 XD 07/13 18:57
※ 編輯: HuangJC 來自: 61.59.179.152 (07/14 02:40)
→ HuangJC :看懂Cake 再回頭看這問題,其實不可能炸;因為 Cake 07/14 02:42
→ HuangJC :自己就這麼做的 :) 07/14 02:42
→ weiyucsie :我是怕你的thtml裡面有函數,class有的沒的 07/14 18:07
→ HuangJC :那些都有,都沒炸 XD ;cake 能做到就有法子require 07/14 18:47
→ weiyucsie :應該是進到global scope了 include的說明裡面有寫 07/14 19:55