如何“通过”类属性到类方法?
如何以以下方式“传递” eventName 到 dbSafe() ?这可能吗? dbSafe() 会是什么样子?
$eventClass->eventName->dbSafe();
我猜 dbSafe() 大致如下所示:
public function dbSafe() {
return mysql_real_escape_string($this);
}
How can I "pass" eventName to dbSafe() in the following fashion? Is this possible? What would dbSafe() look like?
$eventClass->eventName->dbSafe();
I'm guessing dbSafe() would look roughly like this:
public function dbSafe() {
return mysql_real_escape_string($this);
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以将每个属性封装在一个公开 dbSafe() 的新类中。这有点像过于简单的装饰器模式。
You could encapsulate every attribute in a new class that exposed dbSafe(). It's kind of like an oversimplified decorator pattern.
如果
$event
是一个类的实例,具有名为eventName
的属性和名为dbSafe
的方法,那么也许您想要这样做:但是,将数据转义合并到所有类中并不是一个好主意,就像您在这里所做的那样。您确实需要中央数据库管理代码来处理所有转义,这样您就不会忘记它。
If
$event
is an instance of a class with a property calledeventName
and a method calleddbSafe
, then maybe you want to do this:BUT, it's not a great idea to incorporate your data escaping into all of your classes, as you seem to be doing here. You really want central database management code that handles all escaping so you can't forget it.