有谁知道更好地执行的sprintf在PHP?我正在寻找像python中的字符串格式:
print "Hello %(name)s. Your %(name)s has just been created!" % { 'name' : 'world' }
# prints::: Hello world. Your world has just been created!
Run Code Online (Sandbox Code Playgroud)
这样可以避免在不需要的情况下重复相同的变量,例如:
sprintf("Hello %s. Your %s has just been created!", 'world', 'world');
# prints::: Hello world. Your world has just been created!
Run Code Online (Sandbox Code Playgroud)
我想我自己很容易构建这个,但是如果你知道我的意思,我不想重新发明轮子......但我找不到(也许是错误的搜索关键词)任何地方的任何痕迹.
如果有人可以帮忙,我很感激.
干杯,
是否可以通过执行该特定类的代码来取消(清除或取消实例化)类的对象?
我的场景是,由于某种原因,我达到了一个点,对象没有任何意义存在,所以我想确保通过杀死它在内存中的引用不会再次使用它.
这是一个片段示例:
class Foo {
public $bar = "doh!";
function destroy() {
// ???
}
}
$o = new Foo();
echo $o->bar . '\n';
$o->destroy();
echo $o->bar . '\n'; // I expect an error here...
Run Code Online (Sandbox Code Playgroud)
如果我在类代码之外执行"unset"命令,它显然有效:
$o = new Foo();
unset($o);
echo $o->bar . '\n'; // PHP Notice: Undefined property: Foo::$bar in ...
Run Code Online (Sandbox Code Playgroud)
但我尝试在"destroy"方法中执行此操作,通过调用"unset"或创建自定义"__destruct",但没有一个工作.
任何想法都非常受欢迎.
干杯,
我很惊讶地看到这个错误(甚至没有记录在配额中)......
超过100KB,我收到此错误:
TaskTooLargeError: Task size must be less than 102400
Run Code Online (Sandbox Code Playgroud)
关于如何处理这个问题的任何想法?
上下文:电子邮件正文(HTML)作为参数传递给任务队列.