PHP在静态函数中获取子类的名称[重复](PHP Get name of child class in static function [duplicate])
这个问题在这里已有答案:
- 获取父类中的子类名称(静态上下文) 8个答案
- 如何从扩展PHP类中的静态调用中获取类名? 6个答案
这样的事情可能吗?
<? class A { public static function fun() { var_dump(get_class(child)); //bool(false) //should return B } } class B extends A { public static function fun() { parent::fun(); } } B::fun(); ?>
This question already has an answer here:
Is something like this possible?
<? class A { public static function fun() { var_dump(get_class(child)); //bool(false) //should return B } } class B extends A { public static function fun() { parent::fun(); } } B::fun(); ?>
原文:
更新时间:2022-08-26 19:08
最满意答案
(function ($) { var retries = 5; //<--retries $( document).ready(function(){ $('img').one('error', function() { var $image = $(this); $image.attr('alt', 'Still didn\'t load'); if (typeof $image !== 'undefined') { if (typeof $image.attr('src') !== 'undefined') { $image.attr('src', retryToLoadImage($image)); } } }); }); function retryToLoadImage($img) { var $newImg = $('<img>'); var $src = ($img.attr('src')) || ''; $newImg.attr('src', $src); $newImg.one('error', function() { window.setTimeout(function(){ if (retries > 0) { retries--; retryToLoadImage($newImg); } }, 1000); //<-retry interval }); $newImg.one('load', function() { return $newImg.attr('src'); }); } })(jQuery);
我刚才为同一个案例编写了一些代码。 希望它能帮到你!
In the end I solve this issue in a simple (if inelegant) way:
try { canvas.getContext("2d").drawImage (testImage, 0, 0); backgroundLoaded = true; } catch (err) { testImage = new Image (); testImage.src = "placeholder.jpg"; }
The idea is that if an image failed to load, it will fail when rendering it on the canvas, producing an error. When such an error happens, we can create a new image and try again.
相关问答
更多-
PowerShell Foreach循环不能在多次成功尝试后执行(PowerShell Foreach Loop Not Executing after multiple successful attempts)[2023-12-11]
变量$files永远不会被设置,因此它必须是$null (emtpy)。 foreach -loop试图通过$files每个元素,这是什么都没有。 循环不是真的被跳过,没有什么可迭代的。 如果您想遍历$BenchMarksDir所有文件,则必须首先枚举所有文件。 $files = Get-ChildItem -Path $BenchMarksDir -File The variable $files is never set, thus it must be $null (emtpy). The fore ... -
您可以尝试创建一个扩展CI_Controller的自定义控制器,并根据cookie /会话选择适当的语言。 在应用程序/核心文件夹中创建一个名为MY_Controller.php的新文件 class MY_Controller extends CI_Controller { function __construct() { parent::__construct(); //get the language from the cookie if its ...
-
@Pointy和@Gaby的评论是正确的。 我仍然很好奇如何实现这一目标。 这就是我想出的价值所在。 但是未经测试。 var images = $('img'); // Get all images. (you'll want to modify the selector // to work with only the desired images) images.load(function() { // Add a load even ...
-
一旦JSpinner达到极限值,就不会再有任何更改事件。 创建一个javax.swing.SpinnerNumberModel的子类,它具有一个自定义的“setValue(..)”方法,当UI试图设置一个太大的值时通知您的代码。 然后将其安装在您的JSpinner对象中 mySpinner.setModel(new MySpinnerModel()) 但更大的问题是你是否应该这样做。 JSpinner有一个很好理解的UI; 人们(意味着)会习惯它的表现。 获得一个对话框,你必须解雇或其他意想不到的行为可能 ...
-
我发现我必须重新启动nova-conductor服务才能在scheduler_max_attempts应用更改。 I found that I have to restart nova-conductor service to apply changes in scheduler_max_attempts.
-
$test = a(false) || $test = a(true) 将被评估为 $test = ( a(false) || $test=a(true) ) 逻辑运算符总是返回一个布尔值,因此||的结果 表达式将被分配给$test 。 如果你想让上面的表达式将字符串分配给$test ,那么你有使用or 优先级低于赋值运算符(我希望在这种情况下使用这种方式): $test = a(false) or $test = a(true) DEMO 或者您正确设置括号: ($test = a(false)) ...
-
首先要注意的是不要将IP地址作为字符串存储 - 它们是使人类可以读取大量数字的便捷方式。 但是,如果您想开始对地址进行进一步处理(扫描子网中的登录,应用特定国家/地区的验证...),则需要使用IP编号。 SELECT SUM(IF(secs_ago<=300, 1, 0)) as attempts_in_last_5, SUM(IF(secs_ago<=600, 1, 0)) as attempts_in_last_10, SUM(IF(secs_ago<=900, 1, 0)) as att ...
-
我使用这个版本“PushSharp 2.1.2-beta”,我不再得到这个例外了。 I used this version "PushSharp 2.1.2-beta" and I am not getting this exception anymore.
-
(function ($) { var retries = 5; //<--retries $( document).ready(function(){ $('img').one('error', function() { var $image = $(this); $image.attr('alt', 'Still didn\'t load'); if (typeof $image !== 'undef ...
-
我不想打开一个问题,所以对于发现这个问题的人来说,这是一个总结。 我最后在serverfault上重新发布了这个问题(本文) 实际上,他们无法想出任何东西,但我做了一些调查,最终发现它是NFSv4的真正错误,特别是服务器端锁定代码。 我有一个NFS客户端,它每5秒运行一次监控脚本,使用rrdtool将一些数据记录到NFS挂载的文件中。 每次运行时,它都会锁定文件以进行写入,并且服务器已分配(但错误地从未发布)打开的文件描述符。 该脚本(加上另一个运行频率较低的脚本)导致每小时消耗大约900个打开文件,两个月 ...