English 中文(简体)
有可能动态地确定一个类别的名称?
原标题:Possible to dynamically set the name of a class?

I have a mediawiki and phpbb install that I integrated single sign on with successfully.

问题是,他们都有一个用户类别,例如,在媒体上,当我叫Sphpbb 时,他们就犯了一类红学错误。

I got around this by checking if the file is being loaded by mediawiki. If it is, it called a complete copy of the user class called phpbb_user instead. But I m wondering if there is a better way. This is how it currently works

if (!defined( FROM_MEDIAWIKI )){
    class User extends session{
    //user class code
    }

}else{
    class phpbb_user extends session{
    //exact copy of user class code
    }

}

是否有更好的办法做到这一点,不需要2份用户类别的副本?

我知道你不能这样做,但你能否做这样的事情?

$className = (defined( FROM_MEDIAWIKI ))?  phpbb_user  :  User ;

class $className extends session{
    //user class code
}
最佳回答

这是一种黑板,但是,如果界定一切,你可以有一个基类。 然后,你简单地把空子从这一类别中延伸,从而改变名称,不必重复编码。

class __user extends session {
    // user class code
}

if (!defined( FROM_MEDIAWIKI )){
    class User extends __user {}
}else{
    class phpbb_user extends __user {}
}

不过,我热爱看到更好的解决办法。

问题回答

暂无回答




相关问题
Brute-force/DoS prevention in PHP [closed]

I am trying to write a script to prevent brute-force login attempts in a website I m building. The logic goes something like this: User sends login information. Check if username and password is ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

定值美元

如何确认来自正确来源的数字。

Generating a drop down list of timezones with PHP

Most sites need some way to show the dates on the site in the users preferred timezone. Below are two lists that I found and then one method using the built in PHP DateTime class in PHP 5. I need ...

Text as watermarking in PHP

I want to create text as a watermark for an image. the water mark should have the following properties front: Impact color: white opacity: 31% Font style: regular, bold Bevel and Emboss size: 30 ...

How does php cast boolean variables?

How does php cast boolean variables? I was trying to save a boolean value to an array: $result["Users"]["is_login"] = true; but when I use debug the is_login value is blank. and when I do ...

热门标签