我正在寻找从另一个类调用类方法的最佳方法,而不必使用Global来获取类实例,因为我现在理解"全局是邪恶的"!
以下是一些代码来解释它:
class Assets{
public $assets = array();
public function add($asset){
$this->assets[] = $asset;
}
}
Run Code Online (Sandbox Code Playgroud)
现在我想在这里调用Assets/call方法.
$assets = new Assets;
class Form{
public function __construct(){
global $assets;
$assets->add('Form');
}
}
Run Code Online (Sandbox Code Playgroud)
在这种情况下使用Global是不是很糟糕?如果是这样,其他什么方式被认为是最好的?
PS:我只需要使用该类的一个实例; 意味着我不想在第二个类中创建一个新实例.
如果输入iptables -L,输出中将显示以下行:
Chain DOCKER (1 references)
target prot opt source destination
ACCEPT tcp -- anywhere 172.17.0.2 tcp dpt:http-alt
Run Code Online (Sandbox Code Playgroud)
我的容器是公开暴露的,我可以从任何地方(经过测试)请求一个虚拟http服务器。我尝试删除该规则,因此只有80个仅在服务器(localhost:80)内部公开。我试过了 :
root@ns25252:~# iptables -D DOCKER --destination 172.17.0.2 -p tcp --dport 80 -j ACCEPT
iptables: Bad rule (does a matching rule exist in that chain?).
Run Code Online (Sandbox Code Playgroud)
正如错误所暗示的,它找不到匹配的规则。我应如何键入以删除行?
我正在尝试为主文件夹中的每个目录构建一个<ul>列表。<li>这是我的代码:
<?php
$dir = opendir(getEnv("DOCUMENT_ROOT") . "/folder");
while(($file = readdir($dir)) !== false ){
if( is_dir($file) && $file !== "." && $file !== ".." ){
echo "<li>" . $file . "</li>";
}
}
closedir($dir);
?>
Run Code Online (Sandbox Code Playgroud)
/home/example/folder 中有两个目录,但没有被识别为文件夹(当然它们是!)
如果我echo在 while 循环中“”文件,它们就会被打印(它们对于脚本来说很存在,那一侧没有问题)。如果我尝试“ filetype”它们,lstat failed就会抛出一个错误,我在互联网上搜索了它的含义,但最终除了我很难理解的技术支持之外什么也没有。
我不完全确定,但这看起来不对劲:
我有一个名为fraction.h的头文件,其中我存储了一个分数结构和处理它的方法,一个方法用于在文件中写一个分数,在这个函数的签名中,一个参数是一个FILE指针.
fraction.h:
...
const Fraction * fraction_fwrite(const Fraction * f, FILE * file);
...
Run Code Online (Sandbox Code Playgroud)
fraction.c:
#include <stdio.h>
#include "fraction.h"
...
Run Code Online (Sandbox Code Playgroud)
现在,当我尝试编译使用分数的程序时,我收到错误,
这是我在Makefile中的内容:
program_test: fraction.o program_test.o
Run Code Online (Sandbox Code Playgroud)
我当然在program_test.c中包含了fraction.h.但我一直收到这个错误:
fraction.h:34:54:错误:未知类型名称'FILE'
有人可以解释编译器包含文件的不同步骤吗?因为<stdio.h>是在fraction.c中,为什么它会打击这个不明显的类型错误?
我应该包含<stdio.h>在fraction.h中吗?从我的经验来看,这看起来并不合适.
我正在尝试通过扩展本机 Array 来创建自定义 Array 类,但我不知道如何清空元素,这是我的尝试。
class MyArray extends Array {
// for simplicity I just included the bit of code that fails.
reset () {
this = []; // fails of course
}
}
const myarray = new MyArray();
myarray.push(1);
myarray.reset(); // fails because it tries to rewrite `this`
Run Code Online (Sandbox Code Playgroud)
我究竟做错了什么 ?
感谢您的经验,您是否可以说使用DOM对象XHR或jjery的ajax方法更好?
或者它可能取决于性能,可靠性或可用性等要点?我想有一些看法
我有一个数据库,其中包含一个名为带有字段标题的歌曲的表.现在,如果我的网址是(xxx =歌曲的标题),则apache会默默地重定向到类似于:的页面.http://www.foo.com/songs/xxx/song.php?title=xxx
为了修饰URL我将空格转换为下划线(因为我知道某些浏览器显示%20而不是空格,而不是%20实际上%20user%20友好%20ya%20知道20%%20i%20mean).
如果标题包含空格和下划线(例如DJ_underscore fx)并且脚本将其转换DJ_underscore_fx为sql,则会出现问题:
select * from songs where songs.title=xxx
Run Code Online (Sandbox Code Playgroud)
找不到它.
这里的草图更具体:
name_of the song- >
name_of_the_song)<a
href="/songs/name_of_the_song">name_of_the_song</a>)/songs/name_of_the_son- >
/song.php?title=name_of_the_song)select * from songs where songs.title=name_of_the_song)OK你看,有一个在看起来像数据库的条目name_of_the_song,但name_of the song.
如何管理整体,以便我的URL保持清晰,标题字段不限于一定数量的值(可以有空格,下划线,破折号,以及任何东西)?
我正在尝试使用Xlib和Cairo制作屏幕截图,但是我不确定这样做的好方法,"stride"让我很困惑.
这是代码:
#include <stdio.h>
#include <stdlib.h>
#include <malloc.h>
#include <cairo.h>
#include <X11/Xlib.h>
#include <X11/Xutil.h>
int main(int argc, char** argv) {
int x, y;
Display *disp;
Window root;
XWindowAttributes watts;
XImage *image;
cairo_surface_t *surface;
unsigned int width;
unsigned int height;
int stride;
disp = XOpenDisplay(NULL);
root = DefaultRootWindow(disp);
XGetWindowAttributes(disp, root, &watts);
width = watts.width;
height = watts.height;
image = XGetImage(disp, root, watts.x, watts.y, width, height, AllPlanes, ZPixmap);
stride = cairo_format_stride_for_width(CAIRO_FORMAT_RGB24, width);
unsigned char *data = malloc(width * …Run Code Online (Sandbox Code Playgroud) 我知道这听起来有点hacky但有没有办法停止在PHP中执行包含的脚本?在这里给出这个例子
是否有一个功能或一个小技巧用于在这里产生这种效果?
注1:我知道b.php在示例中有一个闭合的条件结构但是如果在该结构之后有代码它将被执行.
注2:退出将停止整个php运行执行,这不是我需要的.
我的应用程序依赖此函数来测试字符串是否为韩语:
const isKoreanWord = (input) => {
const match = input.match(/[\u3131-\uD79D]/g);
return match ? match.length === input.length : false;
}
isKoreanWord('??'); // true
isKoreanWord('mandu'); // false
Run Code Online (Sandbox Code Playgroud)
直到我开始包含中文支持,现在这个功能不连贯:
isKoreanWord('??'); // true
Run Code Online (Sandbox Code Playgroud)
我相信这是因为韩文字符和中文字符混合在同一个Unicode范围内.
true如果输入只包含韩文字符,我该如何更正此函数使其返回?
这是一个完成标题的例子,这是我的函数的内部(我使用postgresql,但我想这是纯SQL语言)
$$
INSERT INTO foo VALUES (DEFAULT, $1) RETURNING id;
INSERT INTO link_foo_to_bar VALUES (1, <?>);
$$ language SQL;
Run Code Online (Sandbox Code Playgroud)
这里要注意两件事,我返回第一个插入的id,如何捕获它以使用返回的id作为第二个插入的第二个参数标记为<?> ?
我想替换光标下当前行的所有文本并c挂起文本,所以我开始输入新代码。但我想保留缩进。
目前我正在使用ddO. 这将删除该行并在插入模式下在光标之前打开一行,这很好,因为 vim 会注意到之前的缩进并按预期放置光标。
但我想使用c类似于ciw(改变内部词),因为认为“改变行”感觉很自然。Vc几乎是我想要的,但它会失去缩进。
任何的想法 ?