使用同一个类的另一个对象(理想情况下在PHP 4.x中)初始化PHP类的实例有什么好方法(以及任何优点和缺点)?
这里initialize()基本上是我想要做的(例子从我的用例非常简化,见下文):
$product = new Product('Widget');
$product2 = new Product('Widget #2');
$product->initialize($product2);
echo $product->name; // echos "Widget #2"
class Product {
var $name;
function __constructor($name) {
$this->name = $name;
}
function initialize($product) {
// I know this cannot be done this way in PHP.
// What are the alternatives and their pros & cons?
$this = $product;
}
}
Run Code Online (Sandbox Code Playgroud)
我知道这可能不是"良好的编程习惯"; 我有20多年的其他语言编程经验,我知道什么是好的,什么不是.所以,如果这样做有意义,我们希望我们不会被挂断.我有一个用例使用一些我无法改变的开源代码,所以请耐心等待我的需要.我实际上是在围绕一些埋藏在WordPress核心深处的非常丑陋的数组代码创建一个OOP包装器.
我正在尝试编写它,以便在将来的版本中,他们可以摆脱丑陋的基于数组的代码,因为每个人都将使用新的API,否则完全封装这些讨厌的数组.但为了使它优雅地工作,我需要能够执行上述操作(在PHP 4.x中)并且我不想编写仅复制属性的代码.
在此先感谢您的帮助.
你们中的许多人都在暗示,clone但除非我误解了这个问题.clone制作副本; 这不是问题的症结所在. …
这个问题在MSChart论坛上一直没有得到回答超过一年.
我不断在图表上获得溢出异常.我正在设置我的图表如下:
Run Code Online (Sandbox Code Playgroud)InstrChart.Legends.Clear(); dataArea = InstrChart.ChartAreas.Add("Instr1"); dataArea.AxisX.MajorGrid.Enabled = false; dataArea.AxisY.MajorGrid.Enabled = false; dataArea.CursorX.IsUserSelectionEnabled = true;我正在添加12个系列,每个系列大约10000点.
当我向下缩放以显示每个系列只有3或4个点时会发生异常.在我释放鼠标按钮进行缩放后,我立即得到以下异常:
Run Code Online (Sandbox Code Playgroud)System.OverflowException was caught Message="Overflow error." Source="System.Drawing" StackTrace: at System.Drawing.Graphics.CheckErrorStatus(Int32 status)(等 - 请参阅上面的链接以获取完整的跟踪.)
我已经删除了图表的所有事件处理程序,没有运气停止从eventuall缩放导致此异常.我已经为图表设置了IsUserSelectionEnabled为false,并且在没有运气的情况下完成了代码缩放.
对这个问题的任何帮助都会很棒.干杯.
无论图表的其余部分是如何配置的,无论何时缩小"太远"(其含义可能会有所不同),任何时候都会出现此异常.有几个人报告了这个问题.异常助手表示它在System.Drawing.dll中.
这里有人有任何线索或解决方法吗?
对于我正在研究的小项目,我需要循环查看列表.对于这个循环的每个元素,我必须通过相同的列表开始另一个循环,前一个元素作为新循环的第一个元素.例如,我希望能够生成这样的东西:
1, 2, 3, 4, 1, 2, 3, 4, 1, ...
2, 3, 4, 1, 2, 3, 4, 1, 2, ...
3, 4, 1, 2, 3, 4, 1, 2, 3, ...
4, 1, 2, 3, 4, 1, 2, 3, 4, ...
1, 2, 3, 4, 1, 2, 3, 4, 1, ...
...
Run Code Online (Sandbox Code Playgroud)
我认为在每个.next()之后复制一个itertools.cycle会保留当前状态,这样我就可以用"外部"循环中的元素开始新的循环.甚至"将循环指针"重置为较旧的位置.我尝试了以下方法:
>>> import itertools, copy
>>> a = itertools.cycle([1, 2, 3, 4])
>>> b = copy.copy(a)
Run Code Online (Sandbox Code Playgroud)
但得到了这个错误:
Traceback (most recent call last):
File "<stdin>", line 1, in <module> …Run Code Online (Sandbox Code Playgroud) 无论出于何种原因,以下请求都没有得到谷歌的回复.但是,如果我将URL粘贴到地址栏中,它可以正常工作.我不确定为什么会这样.谷歌是否过滤了引荐来源标题的请求?
http://maps.googleapis.com/maps/api/geocode/json?sensor=false&address=3122%2C%20Australia
$.ajax({
url:'http://maps.googleapis.com/maps/api/geocode/json?sensor=false&address='+post_code+encodeURIComponent(', Australia'),
success:function(data) {
alert(data);
if(data['status'] == 'OK') {
var location = data['results'][0]['geometry']['location'];
map.panTo(location['lat']+':'+location['lng']);
map.setZoom(8);
}
}
});
Run Code Online (Sandbox Code Playgroud) 这些版本按预期工作:
<DataGridTextColumn Header="Total Units" Binding="{Binding TotalUnits, Mode=OneWay, StringFormat=N0}"/>
<TextBlock Text="{Binding TotalUnits, Mode=OneWay, StringFormat=N0}"/>
Run Code Online (Sandbox Code Playgroud)
当我用标签尝试它时,StringFormat是iqnored,我得到"123.000000"而不是"123".
<Label Content="{Binding TotalUnits, Mode=OneWay, StringFormat=N0}"/>
Run Code Online (Sandbox Code Playgroud)
TotalUnits是十进制.
发生什么了?
有没有内置的东西System.IO.Path只给我文件路径?
例如,如果我有 string
@ "C:\网络服务器\ PUBLIC\myCompany的\ CONFIGS\promo.xml"
是否有任何BCL方法可以给我
"C:\网络服务器\ PUBLIC\myCompany的\ CONFIGS \"?
更新:在评论中建议我为此创建一个wiki.我已经完成了,你可以在这里找到它(如果你想密切关注和/或贡献).
我之前从未做过这样的事情,所以我完全放弃它.
我以前从来没有做过这样的事,所以请
我想要开放的"标准"或"语言",或者......好吧,我真的不知道该怎么称呼它......使表单验证更容易.我称之为VRS(验证规则表),但在这个阶段,一切都可以协商.
我们的想法是创建一张规则,类似于CSS,定义如何验证表单.这将需要
像这样的系统的好处是
首先是第一件事.语法/规范应该是什么样的.
我在网上看到这种方式的方式是可以将VRS文件指定为隐藏字段,并且应用程序在处理之前将提供的表单数据通过VRS处理器进行路由.
举个例子,你可以验证"name"字段的内容类型是这样的
name {
content-type: alpha;
}
Run Code Online (Sandbox Code Playgroud)
content-type可以是以下三个值之一:alpha,numeric或alpha-numeric.
希望这是有道理的.我之前从未做过这样的事情所以我渴望得到别人的意见.就这一点而言,我已经到了
------------------------------------------------------------
content-type: (string) alphanumeric | alpha | numeric
Restricts content to either numeric, text or alphanumeric.
------------------------------------------------------------
is-fatal: BOOL
If the rule fails, is it fatal? This could be really useful
for AJAX responses.
------------------------------------------------------------
allow-null: BOOL
wether a field can be empty or not. Good for required fields
and checkboxes
------------------------------------------------------------
pattern-match: (string) email …Run Code Online (Sandbox Code Playgroud) 使用PHP和MySQL我试图从下面列出的所有4个表中的数字和类型列中获取所有不同的值:
table_1
ID|t1_number|t1_type
1|1|new
2|1|old
3|2|new
4|3|new
5|1|old
table_2
ID|t2_number|t2_type
1|1|future
2|1|new
3|3|past
4|3|new
5|1|new
table_3
ID|t3_number|t3_type
1|1|past
2|1|new
3|1|new
4|1|new
5|1|old
table_4
ID|t4_number|t4_type
1|1|new
2|4|new
3|3|old
4|2|new
5|1|new
Run Code Online (Sandbox Code Playgroud)
我想从上面的表中得到的值是:
数字:1,2,3,4
类型:新的,旧的,未来的,过去的
这是我到目前为止所拥有的; 但我不确定SQL是否正确或如何格式化while循环以获取值.
$sql = "SELECT DISTINCT table_1.t1_number, table_2.t2_number, table_3.t3_number, table_4.t4_number, table_1.t1_type, table_2.t2_type, table_3.t3_type, table_4.t4_type
FROM table_1
JOIN table_2
JOIN table_3
JOIN table_4";
$result = @mysql_query($sql, $con) or die(mysql_error());
while($row = mysql_fetch_array($result)) {
$numbers= $row[?????????];
}
Run Code Online (Sandbox Code Playgroud) 如果你无法从一个NSSet中获取objectAtIndex的对象,那么如何检索对象呢?