当我打电话self::$parameter = 1;给__set不叫.
有办法解决吗?
在file.php:
call()...
Run Code Online (Sandbox Code Playgroud)
如何获得file.php内部的绝对路径call()?
注意call()可能在另一个文件中定义.
another.php:
function call(){..}
Run Code Online (Sandbox Code Playgroud)
file.php:
include(path_to_another.php);
call();
Run Code Online (Sandbox Code Playgroud) 它的功能非常强大,我担心它的稳定性和性能.
你怎么看?
UPDATE
我正在做的是这样的:
$old_dir = getcwd();
chdir( dirname($included_file) );
include ( $included_file );
chdir( $old_dir );
Run Code Online (Sandbox Code Playgroud)
基本上它只是这样include ( $included_file );,但在内部$included_file它找不到3.php与它本身位于同一目录中,所以我手动设置cwd并且它工作.但是如果我找到它无法找到的原因会很好至于为什么debug_backtrace需要,因为3.php它被另一个包含func,因为相对路径不起作用,它必须debug_backtrace用来获取包含文件路径,最后使用如下所述的绝对路径.
重现并不容易,因为上面的代码是在一个方法的上下文中,而且还有更多......如果没有其他人遇到过这种问题我想停在这里,无论如何,成本只是额外的3线,没什么大不了的.
这有效:
#include <iostream>
using namespace std;
Run Code Online (Sandbox Code Playgroud)
但这失败了:
#include <stdio>
Run Code Online (Sandbox Code Playgroud)
什么时候.h不需要?
关于命名空间问题,我没有找到这样的逻辑cstdio:
#pragma once
#ifndef _CSTDIO_
#define _CSTDIO_
#include <yvals.h>
#ifdef _STD_USING
#undef _STD_USING
#include <stdio.h>
#define _STD_USING
#else /* _STD_USING */
#include <stdio.h>
#endif /* _STD_USING */
// undef common macro overrides
#undef clearerr
#undef feof
#undef ferror
#undef getc
#undef getchar
#undef putc
#undef putchar
#define _HAS_CONVENTIONAL_CLIB 1
#define _IOBASE _base
#define _IOPTR _ptr
#define _IOCNT _cnt
#ifndef _FPOSOFF
#define _FPOSOFF(fp) ((long)(fp))
#endif /* _FPOSOFF …Run Code Online (Sandbox Code Playgroud) 据说下面的代码会导致分段违规:
#include <stdio.h>
#include <string.h>
void function(char *str) {
char buffer[16];
strcpy(buffer,str);
}
int main() {
char large_string[256];
int i;
for( i = 0; i < 255; i++)
large_string[i] = 'A';
function(large_string);
return 1;
}
Run Code Online (Sandbox Code Playgroud)
它的编译和运行方式如下:
gcc -Wall -Wextra hw.cpp && a.exe
Run Code Online (Sandbox Code Playgroud)
但没有任何结果.
注意
上面的代码确实会覆盖ret地址等等,如果你真的明白它下面会发生什么.
该RET地址将0x41414141要具体.
重要 这需要深刻的堆栈知识
我想创建一个这样的图像:
从这样的图像:
替代文字http://internationalpropertiesregistry.com/Server/showFile.php?file=%2FUpload%2Funtitled.jpgb523c7595dd8e7514e1c6d51a83161a3.jpeg
UPDATE
这里是由真实发生了什么255-img,但结果不完全匹配:
替代文字http://internationalpropertiesregistry.com/Server/showFile.php?file=%2FUpload%2Funtitled.jpg61f9edbeb4f0285c2a1772cced3ce393.jpeg
test.c:
#include "file.h"
Run Code Online (Sandbox Code Playgroud)
在上面的语句中,将搜索哪些目录?
我想要test.c搜索locates 的目录,对吗?
但这就是全部吗?
顺便说一下,使用头文件有什么好处?Java不需要头文件......