假设我有一个类,它有一个数字子类.
我可以实例化这个类.然后我可以将其__class__属性设置为其中一个子类.我已经在类活动对象上有效地将类类型更改为其子类的类型.我可以调用它上面的方法来调用子类的那些方法的版本.
这样做有多危险?这看起来很奇怪,但做这样的事情是不对的吗?尽管能够在运行时更改类型,这是否应该完全避免使用该语言的功能?为什么或者为什么不?
(根据回复,我会发布一个更具体的问题,关于我想做什么,以及是否有更好的选择).
我尝试从iframe重新加载父网页.这是我的代码:
<script>
$(document).ready(function() {
window.parent.location.href = window.parent.location.href;
});
</script>
Run Code Online (Sandbox Code Playgroud)
但它不起作用.Firebug说:拒绝访问属性'href'的权限
我在同一领域,所以问题是什么?我尝试在Wordpress主题中做到这一点.
我想z在以下代码中创建一个全局变量:
#!/bin/bash
z=0;
find $1 -name "*.txt" | \
while read file
do
i=1;
z=`expr $i + $z`;
echo "$z";
done
echo "$z";
Run Code Online (Sandbox Code Playgroud)
最后一个语句总是输出"0".为什么?
我有JSON输出编码.
$responseJSON
{"status":1,"content":{"sessionid":"4c86cf1acac07811db6ec670e0b9cdd2"}}
Run Code Online (Sandbox Code Playgroud)
现在我对它进行解码
$decoded=json_decode($responseJSON);
print_r($decoded)
Run Code Online (Sandbox Code Playgroud)
我明白了
stdClass Object (
[status] => 1
[content] => stdClass Object (
[sessionid] => 4c86cf1acac07811db6ec670e0b9cdd2
)
)
Run Code Online (Sandbox Code Playgroud)
我不想那样解码.
如何在没有这些stdClass标记的情况下解码为普通数组?
我想创建这两个表,但我收到一个错误,说明由HOLD的外键引用的SECTION键不是主键.正如在查询中看到的那样,它们是主键.我怎么解决这个问题?
create table SECTION(
ID integer foreign key references TERM(ID),
CID integer foreign key references COURSE(CID),
SECT integer,
constraint PK_SECTION primary key (ID,CID,SECT),
);
create table HOLD(
NAME varchar(30) foreign key references INSTRUCTOR(NAME),
ID integer foreign key references SECTION(ID),
CID integer foreign key references SECTION(CID),
SECT integer foreign key references SECTION(SECT),
constraint PK_HOLD primary key (NAME,ID,CID,SECT),
);
Run Code Online (Sandbox Code Playgroud)