我试图从一个闭包中引用一个对象的私有变量.下面的代码似乎有效,但它抱怨Fatal error: Cannot access self:: when no class scope is active in test.php on line 12和Fatal error: Using $this when not in object context in test.php on line 20.
任何想法如何使用闭包完成相同的结果,同时保持变量私有和没有帮助函数(击败私有变量的整个想法).
class MyClass
{
static private $_var1;
private $_var2;
static function setVar1( $value )
{
$closure = function () use ( $value ) {
self::$_var1 = $value;
};
$closure();
}
function setVar2( $value )
{
$closure = function () use ( $value ) {
$this->_var2 = $value; …Run Code Online (Sandbox Code Playgroud) 我想通过为Objective-C Blocks创建一个类别来添加函数.
__block int (^aBlock)(int) = ^int( int n ){
if( n <= 1 ) return n;
return aBlock( n - 1 ) + aBlock( n - 2 );
};
Run Code Online (Sandbox Code Playgroud)
而不是只允许正[aBlock copy],[aBlock retain],[aBlock release],[aBlock autorelease].我可以这样做:
[aBlock mapTo:anArray];
Run Code Online (Sandbox Code Playgroud)
可能的类别
@interface UnknownBlockClass (map)
- (NSArray *)mapTo:(NSArray *)array_;
@end
Run Code Online (Sandbox Code Playgroud) 我想为我的Magento项目创建存储库.根目录中有很多文件夹和文件,我只更改一个文件夹的时间:app/code/local /
我想忽略的其他一切.但是......不能.我的.gitignore文件:
*
!app/code/local/
!app/code/local/*
Run Code Online (Sandbox Code Playgroud)
然后,当我尝试将文件夹添加到repo时,我收到一个错误:
git add app/code/local/Mds/
The following paths are ignored by one of your .gitignore files:
app
Use -f if you really want to add them.
fatal: no files added
Run Code Online (Sandbox Code Playgroud)
任何人都可以帮忙吗?
我想知道如何找到一组具有有限数量匹配的给定正则表达式的所有匹配.
例如:
所有这些例子都可以假设他们从一开始就^结束$
`hello?` -> (hell, hello)
`[1-9][0-9]{0,3}` -> (1,2,3 ..., 9998, 9999)
`My (cat|dog) is awesome!` -> (My cat is awesome!, My dog is awesome!)
`1{1,10}` -> (1,11, ..., 111111111, 1111111111)
`1*` -> //error
`1+` -> //error
`(1|11){2}` -> (1,11,111,1111) //notice how it doesn't repeat any of the possibilities
Run Code Online (Sandbox Code Playgroud)
如果有一种方法可以检索计算正则表达式的唯一解,或者是否有办法确定正则表达式是否具有有限解,那么我也会感兴趣.
如果算法可以解析任何正则表达式会很好,但正则表达式的强大的子集将是好的.
我对这个问题的PHP解决方案感兴趣,但其他语言也没问题.
编辑:
我在我的Formal Theory课程中学到了可以用来实现正则表达式(以及其他常规语言)的DFA.如果我可以将正则表达式转换为DFA,那么解决方案对我来说似乎相当直接,但这种转变对我来说似乎相当棘手.
编辑2:
感谢所有建议,请参阅我关于公共github项目的帖子,我正在努力"回答"这个问题.
在计算两个任意正则表达式是否有任何重叠的解决方案(假设它是可能的).
例如,这两个正则表达式可以通过强力显示没有交叉点,因为这两个解决方案集是可计算的,因为它是有限的.
^1(11){0,1000}$ ? ^(11){0,1000}$ = {}
{1,111, ..., ..111} ? {11,1111, ..., ...11} = {}
{} = {}
Run Code Online (Sandbox Code Playgroud)
但用{0,1000}通过*删除一个蛮力解决方案的可能性,所以一个更聪明的算法必须创建.
^1(11)*$ ? ^(11)*$ = {}
{1,^1(11)*$} ? {^(11)*$} = {}
{1,^1(11)*$} ? {11,^11(11)*$} = {}
{1,111,^111(11)*$} ? {11,^(11)*$} = {}
.....
Run Code Online (Sandbox Code Playgroud)
在另一个类似的问题中,一个答案是计算交集正则表达式.这可能吗?如果是这样,怎么会写一个算法来做这样的事情?
我认为这个问题可能是暂停问题的结果.
编辑:
我已经使用已接受的解决方案为示例问题创建了DFA.可以很容易地看到如何在状态图上使用BFS或DFS M_3来确定是否可以达到最终状态M_3.

说明
PHP在其语法中有一些漏洞,偶尔在开发过程中,程序员会介入它们.这可能会导致很多挫折,因为这些语法漏洞似乎无缘无故地存在.例如,一个人不能轻易地创建一个数组并在同一行上访问该数组的任意元素(func1()[100]不是有效的PHP语法).此问题的解决方法是使用临时变量并将语句分成两行,但有时这会导致非常详细,笨重的代码.
挑战
我知道其中一些漏洞(我确信还有更多漏洞).甚至很难提出解决方案,更不用说代码高尔夫风格了.获胜者是所有四个语法孔中总字符数最少的人.
规则
$output = ...;,哪里...不包含任何;.eval允许)E_STRICT | E_ALL.语法孔
$output = func_return_array()[$key];- 访问函数返回数组的任意偏移量(string或integer)$output = new {$class_base.$class_suffix}(); - 用于创建新类的任意字符串连接$output = {$func_base.$func_suffix}(); - 任意字符串连接被称为函数$output = func_return_closure()(); - 调用从另一个函数返回的闭包我有N可伸缩的方形瓷砖(按钮),需要放在固定大小的矩形表面(工具箱)内.我想以相同的尺寸呈现按钮.
我怎样才能解决瓷砖的最佳尺寸,这将提供瓷砖覆盖的矩形表面的最大区域.
language-agnostic algorithm user-interface geometry maximize
语言是PHP.我有一个foreach($ a为$ b)和另一个foreach($ c为$ d => $ e).我如何将它们组合成一个整体.我厌倦了foreach(($ a as $ b)&&($ c as $ d => $ e)),但那是垃圾.
我有一个包含在UIView对象A中的UIView对象.我希望能够触摸X并将其从对象A中移除并将其移动到对象B(另一个UIView)中.对象A和B都在同一个超级UIView中.
A B
_____ _____
| | | |
| X | -> | |
|___| |___|
Run Code Online (Sandbox Code Playgroud)
这就是我到目前为止所拥有的.
@implementation X_UIView
float deltaX;
float deltaY;
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
[self.superview.superview addSubview:self]; //pop dragged view outside of container view
CGPoint beginCenter = self.center;
UITouch * touch = [touches anyObject];
CGPoint touchPoint = [touch locationInView:self.superview];
deltaX = touchPoint.x - beginCenter.x;
deltaY = touchPoint.y - beginCenter.y;
}
- (void) touchesMoved:(NSSet*)touches withEvent:(UIEvent*)event {
UITouch * touch = [touches anyObject];
CGPoint touchPoint = [touch …Run Code Online (Sandbox Code Playgroud) 我已经设置了SDK附带的示例Web服务器(https://github.com/googlecast/),它可以使用它们提供的示例媒体文件.当我尝试使用示例m3u8文件时,它失败了:
{"code":"session_error","description":"LOAD_FAILED","details":null}`
Run Code Online (Sandbox Code Playgroud)
两个URL在Safari中加载正常.是否不支持此类流媒体?有没有办法获得更详细的错误消息.
php ×4
algorithm ×3
objective-c ×2
regex ×2
arrays ×1
chromecast ×1
closures ×1
cocoa ×1
cocoa-touch ×1
code-golf ×1
dfa ×1
foreach ×1
function ×1
geometry ×1
git ×1
gitignore ×1
google-cast ×1
intersection ×1
javascript ×1
m3u8 ×1
maximize ×1
scope ×1
set ×1
syntax ×1
uikit ×1
uiview ×1