是否可以创建一个PHP函数,通过引用获取所有参数的可变数量的参数?
它没有帮助我通过引用接收一个值数组的函数,也没有一个函数将其参数包含在一个对象中,因为我正在处理函数组合和参数绑定.不要考虑呼叫时间传递参考.那东西甚至不应该存在.
php parameter-passing pass-by-reference variadic-functions function-parameter
我正在使用Visual Studio 2010 Professional.我需要在本地报告中添加一个参数.我发现的所有信息都说使用报告参数对话框.大!!看起来我应该选择rdlc文件然后显示Report Menu选项,然后从菜单中选择对话框.但它不在那里.它在哪里?我有一个Microsoft示例的代码,如果需要可以编辑XML但看起来我不需要.救命!!
所以,我刚刚开始学习Java,我发现没有"通过引用传递"这样的东西.我正在将一个应用程序从C#移植到Java,原始应用程序有一个"ref"或"out"参数的整数和双精度数.
起初我以为我可以传入"整数"或"双精度",由于这是一个引用类型,因此值将被更改.但后来我了解到那些引用类型是不可变的.
那么,我创建了一个"MutableInteger"类和一个"MutableDouble"类,并将它们传递给了我的函数.它有效,但我想我必须违背该语言的原始设计意图.
一般糟糕的设计是"通过参考"吗?我该如何改变自己的思维方式?
拥有这样的函数似乎是合理的:
bool MyClass::changeMyAandB(ref int a, ref int b)
{
// perform some computation on a and b here
if (success)
return true;
else return false;
}
Run Code Online (Sandbox Code Playgroud)
这是糟糕的设计吗?
在Windows Phone 7 Silverlight应用程序中,我使用调用新页面
NavigationService.Navigate(new Uri("/View/SecondPage.xaml", UriKind.Relative));
Run Code Online (Sandbox Code Playgroud)
现在我想将参数传递给新页面.我理解一个简单的参数可以使用:
NavigationService.Navigate(new Uri("/View/TilgungsratePage.xaml?id=4711", UriKind.Relative));
Run Code Online (Sandbox Code Playgroud)
并使用在新页面中阅读
protected override void OnNavigatedTo(Microsoft.Phone.Navigation.PhoneNavigationEventArgs e)
{
base.OnNavigatedTo(e);
String id = NavigationContext.QueryString["id"];
}
Run Code Online (Sandbox Code Playgroud)
对于简单参数,这没关系,但如何传递列表?
复杂的物体?
什么,但简单的价值观?
我正在使用SQLAlchemy connection.execute(sql)将选择结果转换为映射数组.有以下代码
def __sql_to_data(sql):
result = []
connection = engine.connect()
try:
rows = connection.execute(sql)
for row in rows:
result_row = {}
for col in row.keys():
result_row[str(col)] = str(row[col])
result.append(result_row)
finally:
connection.close()
return result
Run Code Online (Sandbox Code Playgroud)
例如
__sql_to_data(sql_get_scan_candidate)Run Code Online (Sandbox Code Playgroud)给我很好的数据结构(当然我用它来处理小数据集).但是为了向sql添加参数,我目前正在使用格式,例如
return __sql_to_data(sql_get_profile.format(user_id))Run Code Online (Sandbox Code Playgroud)
问题 如何修改程序以使类似的东西成为可能
return __sql_to_data(sql_get_profile,user_id)Run Code Online (Sandbox Code Playgroud) 如果你要查看这段代码,
int x = 0;
function(x);
std::cout << x << '\n';
Run Code Online (Sandbox Code Playgroud)
您将无法通过任何语法方式验证参数x是通过引用传递还是通过值传递.您可以肯定的唯一方法是查看函数声明或函数定义.
这是一个简单的例子,我认为这可能是一个问题:
std::string Lowercase(std::string str); //<- this is hidden away in code; probably in a different file.
int main(){
std::string str = "HELLO";
Lowercase(str);
std::cout << str << '\n'; //<- Bug! we expected to output "hello". The problem is not very easy to spot, especially when a function name sounds as though it will change the passed in value.
}
Run Code Online (Sandbox Code Playgroud)
为了避免必须在函数调用和函数声明(或在某些情况下,文档)之间跳转以理解函数行为,有没有办法在函数调用的语法中显式地记录参数是期望改变(即参考参数)或发送副本(即通过值传递)?
我意识到还有一个选择传递const&,它具有类似于传递值的概念,因为传入的变量在函数调用之后不会更改其值.
我确信语言中有各种各样的情况可能会增加理解参数传递的复杂性 - 但我很好奇,有没有办法以我想要的方式解决这个问题? …
我做了一个运行php脚本的bash脚本.没有参数它工作正常但是当我添加参数(id和url)时,有一些错误:
PHP Deprecated: Comments starting with '#' are deprecated in /etc/php5/cli/conf .d/mcrypt.ini on line 1 in Unknown on line 0
Could not open input file: /var/www/dev/dbinsert/script/automatisation.php? id=1
Run Code Online (Sandbox Code Playgroud)
我像这样从bash运行php脚本:
php /var/www/dev/dbinsert/script/automatisation.php?id=19&url=http://bkjbezjnkelnkz.com
Run Code Online (Sandbox Code Playgroud) 什么是更好的做法?
self.call(1, True, "hi")
Run Code Online (Sandbox Code Playgroud)
要么
self.call(1, True, "hi",)
Run Code Online (Sandbox Code Playgroud)
以下情况如下:
self.call(
1,
True,
"hi"
)
Run Code Online (Sandbox Code Playgroud)
要么
self.call(
1,
True,
"hi",
)
Run Code Online (Sandbox Code Playgroud)
?
在数据结构中添加尾随逗号的原因对我来说很熟悉,但是函数调用呢?
有没有人建议在C#中使用params进行方法参数传递.我正在考虑为前6个参数进行重载,然后使用params功能进行7次重载.我的理由是避免params功能所需的额外数组分配.这适用于一些高性能的实用方法.有什么建议?创建所有重载是浪费代码吗?
我有一个登录屏幕,我想将登录ID从LoginController传递给MainController,所以我可以访问一些函数来更改密码等等.
我像这样加载控制器:
FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource("fxml/Main.fxml"));
Parent root = (Parent)fxmlLoader.load();
Scene scene = new Scene(root);
stage.setScene(scene);
stage.show();
Run Code Online (Sandbox Code Playgroud)
Main.fxml受限于MainController.java.有没有办法可以传递我需要的用户ID,并在控制器的initialize()方法上访问它?
parameters ×2
php ×2
python ×2
bash ×1
c ×1
c# ×1
c++ ×1
c++11 ×1
coding-style ×1
function ×1
java ×1
javafx-2 ×1
overloading ×1
params ×1
shell ×1
sql ×1
sqlalchemy ×1