问题列表 - 第14783页

php - 从另一个脚本访问已经实例化的类的属性而无需重新实例化的任何方法?

我有页面main.html,它是特定服务器的客户端应用程序.main.php是一个有三个框架的窗口.

main.html中

<frameset frameborder=no border=0>
 <frame name='top1' src='top1.php' frameborder=no scrolling=no>
        <frame name='top2' src='top2.php' frameborder=no scrolling=no>
 <frame name='firstpage' src='firstpage.php' frameborder=no scrolling=auto>
</frameset>
Run Code Online (Sandbox Code Playgroud)

firstpage.php

<?php 
....
....
require_once("connection.php");
// connection.php is a class which opens a socket and establishes with another server.
set_time_limit(0);
ignore_user_abort();

function parse($line) {
//parses $line returns $a which contains some data etc
....
return $a;
}

$connect= new Connection();
.....
$line=$connect->socket_read(1028);
.....
while ($i<200) {
$GLOBALS[userdata][$i]=parse($line);
.......
}
?>
Run Code Online (Sandbox Code Playgroud)

firstpage.php是一个大脚本,我已经修剪了firstpage.php的大部分,原因是易读性.connect.php和firstpage.php正如我想要的那样工作.

我需要在top1.php和top2中使用$ GLOBALS [userdata]进行进一步处理.无论如何我可以访问$ GLOBALS [userdata]而不再实例化connect.php吗?(我希望在top1.php和top2.php中进行的数据处理不能在firstpage.php中完成,原因我在这里无法讨论.)我无法重新实现connect.php,因为从服务器到firstpage.php的数据将会不要被我的服务器重新发送.

我已经意识到,因为firstpage.php无限运行$ GLOBALS没有写入.在$ GLOBALS …

php class instantiation

0
推荐指数
1
解决办法
185
查看次数

linq的foreach结果不起作用

不知道这里有什么问题,当我运行应用程序时,在foreach循环中指向"查询中的var结果"时说"指定的方法不受支持".请帮忙...

var query = from c in entities.Customer
            select c.CustomerName;

List<string> customerNames = new List<string>();

foreach (var result in query)
{
    customerNames.Add(result.ToString());  
}
Run Code Online (Sandbox Code Playgroud)

编辑:使用ToList()也会给出相同的错误.

linq list

5
推荐指数
1
解决办法
5073
查看次数

如何从python ctypes中取消引用内存位置?

我想在python ctypes中复制以下c代码:

main() {
  long *ptr = (long *)0x7fff96000000;
  printf("%lx",*ptr);
}
Run Code Online (Sandbox Code Playgroud)

我可以弄清楚如何将此内存位置称为函数指针,但不仅仅是执行正常的取消引用:

from ctypes import *
"""
>>> fptr = CFUNCTYPE(None, None)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python2.6/ctypes/__init__.py", line 104, in CFUNCTYPE
    class CFunctionType(_CFuncPtr):
TypeError: Error when calling the metaclass bases
    item 1 in _argtypes_ has no from_param method
"""
fptr = CFUNCTYPE(None, c_void_p) #add c_void_p since you have to have an arg
fptr2 = fptr(0x7fff96000000)
fptr2(c_void_p(0))
#python: segfault at 7fff96000000 ip 00007fff96000000 …
Run Code Online (Sandbox Code Playgroud)

python ctypes ffi

13
推荐指数
1
解决办法
2万
查看次数

找到非零值字典中最大键的有效方法

我是新的Python,并试图以更加Pythonic和高效的方式实现代码.给定带有数字键和值的字典,找到具有非零值的最大键的最佳方法是什么?

谢谢

python dictionary

6
推荐指数
2
解决办法
2万
查看次数

传统日志记录与AOP日志记录

我正在开始这个新项目,我们正在逐步淘汰我们的日志/调试方法,我想在SO上给你们其他人提出问题,给出

private final static Logger logger = LoggerFactory.getLogger(getClass());
...
public void doSumething(){
...
if(logger.isDebugEnabled())
    logger.debug("...");
}
Run Code Online (Sandbox Code Playgroud)

要么

 @After("execution(* *.doSomething())")
    public void logAfter(JoinPoint jp){
        logger.debug("...");
    }
Run Code Online (Sandbox Code Playgroud)

AOP方法真的比使用传统方法更好吗?或者AOP在特定用例中是否优于日志记录/分析?

logging aop

17
推荐指数
2
解决办法
7604
查看次数

转换英国时间(BST和GMT)表示为UTC的字符串(在C#中)

我必须使用遗留数据库中的一些日期和时间.它们表示为字符串.日期是dd/MM/yy.时间是HH:mm.

我想从数据库中提取它们后立即将这些转换为UTC.我正在研究美国的系统,所以需要一个共同的时间.

我面临的问题是如何将它们转换为UTC DateTime值.我可以进行解析等.我遇到的真正问题涉及时区.

我正在尝试使用以下方法:

DateTime ukTime = // Parse the strings in a DateTime value.
TimeZoneInfo timeZoneInformation = TimeZoneInfo.FindSystemTimeZoneById("GMT Standard Time");
DateTimeOffset utcTime = new DateTimeOffset(ukTime, timeZoneInformation.BaseUtcOffset);
Run Code Online (Sandbox Code Playgroud)

但是,如果日期在英国夏令时期间,则会给出不正确的值.

我可以在这些日期使用"GMT日光时间",但这需要我知道切换的时间.我敢肯定必须有一种不那么费力的方式.

因为我没有使用具有英国时间设置的机器,所以我不能依赖当地时间.

基本上,我需要这样的东西:

// Works for both GMT (UTC+0) and BST (UTC+1) regardless of the regional settings of the system it runs on.
DateTime ParseUkTimeAsUtcTime(string date, string time)
{
    ...
}
Run Code Online (Sandbox Code Playgroud)

我已经搜索了帖子,但找不到任何直接解决这个问题的内容.当然这也是EST,EDT等问题?

.net c# timezone

10
推荐指数
1
解决办法
8628
查看次数

.NET中线程中止和中断的区别

Thraed.Abort()和Thread.Interrupt()之间有什么区别?如何以线程安全方式调用它们.如果提供简单的示例,它将会有所帮助.

c# multithreading

14
推荐指数
2
解决办法
1万
查看次数

共享指针和性能

我现在一直在使用共享指针,我的程序中存在性能问题...所以我想知道共享指针是否导致性能下降.如果是这样,那有多难?非常感谢.

我的程序是多线程的,使用std :: tr1 :: shared_ptr

c++ performance memory-management cpu-usage shared-ptr

8
推荐指数
4
解决办法
2891
查看次数

使用免费时,内存使用量不会减少?

不知何故,此调用free()无效.我在Windows上运行此应用程序并在任务管理器中使用内存,但在调用后没有看到内存使用量减少free().

int main(int argc, char *argv[])
{
    int i=0;
    int *ptr;

    ptr = (int*) malloc(sizeof(int) * 1000);

    for (i=0; i < 1000; i++)
    {
        ptr[i] = 0;
    }

    free(ptr); // After this call, the program memory usage doesn't decrease

    system("PAUSE");

    return 0;
}
Run Code Online (Sandbox Code Playgroud)

c++ memory-leaks

2
推荐指数
1
解决办法
379
查看次数

使用SimplyVBUnit在VB 6中进行单元测试

我最近决定开始使用一些灯光单元测试来看看它是否为我们的项目增加了任何价值,但是我找不到SimplyVBUnit的文档.有什么建议?

vb6 unit-testing simplyvbunit

7
推荐指数
1
解决办法
6516
查看次数