欢迎各位兄弟 发布技术文章

这里的技术是共享的

You are here

strict warning: Only variables should be passed by reference in C:\wamp\www\drupal\includes\locale 有大用

Drupal汉化的时候 strict warning: Only variables should be passed by reference in C:\wamp\www\drupal\includes\locale.inc on line 615.这个问题怎么解决啊 在线等啊

这是可能是临时文件夹设置的原因。
你设置一下drupal的临时文件,用相对路径,使其在drupal 的文件夹下。就可以了。 
如设置临时文件夹: abc   (开头不要带/)


可能是PHP版本的问题,615行这个地方应该有个引用的代码,把这行代码拆分为两行来写。。

---   $default = array_shift(array_keys($languages));
+++  $array_keys_languages = array_keys($languages);
+++  $default = array_shift($array_keys_languages);

diff --git a/modules/views.page_title.inc b/modules/views.page_title.inc

diff --git a/modules/views.page_title.inc b/modules/views.page_title.inc
index 57a55b1..389fb08 100644
--- a/modules/views.page_title.inc
+++ b/modules/views.page_title.inc
@@ -30,7 +30,9 @@ function views_page_title_pattern_alter(&$pattern, &$types) {
       $h = $view->argument;
 
       // Splice the arguments and get the key for the current arg.
-      $h = array_shift(array_splice($h, count($args)-1, 1));
+      $hh = array_splice($h, count($args)-1, 1);
+      $h = array_shift($hh);
+
 
       // Get the Page Title Pattern from the options array for this handler
       $pattern = isset($h->options['page_title_pattern']) ? $h->options['page_title_pattern'] : $pattern;
来自 https://zhidao.baidu.com/question/541715246.html

我的网页吐出多次发生:

严格警告:只有变量才能通过reference_formats_filter_process_format()(第132行/ drupal / sites / all / modules / better_formats / better_formats.module)传递。

警告指出的一行是:

$element['format']['format']['#default_value'] = array_shift(array_keys($options));

注释

gaas的照片

 

问题摘要:查看更改
 
steinmb的照片

 

状态:活性»关闭(不会修复)

已经在dev中解决了 PLS。测试与最新的开发。如果问题仍然存在,重新打开。

amanire的照片

 

我很想看到这个修复程序进入稳定版本。我不想在生产站点上使用开发分支或修补模块。有什么办法可以帮忙吗?

没有Sssweat的图片

 

所有的警告是说,你需要传递/使用一个变量。所以你要做的就是创建一个变量并使用它。

只需用以下两行替换第132行

$test = array_keys($options);
$element['format']['format']['#default_value'] = array_shift($test);
没有Sssweat的图片

 

状态:已关闭(不会修复)»关闭(固定)
 
amanire的照片

 

#4工作完美,感谢camster!

drupov的头像

 

状态:关闭(固定)»关闭(重复)
amanire的照片

 

请在稳定版本中修复此错误。Мany人害怕使用dev版本。谢谢。

来自 https://www.drupal.org/node/2194237

How to resolve Drupal strict warning: Only variables should be passed by reference in include()?

  • 13
 

Although my code is working fine I get a strict warning:

Strict warning: Only variables should be passed by reference in include() (line 18 of /home/sites/dev/theparce/sites/all/themes/parce/block–block–3.tpl.php).

Here is my code:

 

1
2
3
4
5
6
7
8
9
10
11
12
if ($user_gallery) {
 
print render(node_show($user_gallery)); // Line 18
 
print drupal_render ($user_gallery_edit);
}
 
else {
 
print drupal_render($user_gallery_new);
 
}
 Bruce Cooper Asked on October 5, 2015 in Drupal.
 
1 Answer(s)
  • 11
 
 

Greetings,

This warning is not Drupal related. It is strict PHP and can be explained in the following article:

http://www.php.net/manual/en/language.references.pass.php

The simplest solution would be to split your code. Instead of using :

1
print render(node_show($user_gallery))

You should use:

1
2
$page = node_show($user_gallery);
 print render($page);
 Russel Thomas Answered on October 5, 2015.

来自 https://www.tmdhosting.com/kb/question/how-to-resolve-drupal-strict-warning-only-variables-should-be...



 
 

我收到以下错误:

严格警告:只能在include()(/home/sites/dev/theparce/sites/all/themes/parce/block--block--3.tpl.php中的第18行)中引用变量。

这是导致该错误的块代码。

if ($user_gallery) {
  print render(node_show($user_gallery));  // Line 18
  print drupal_render ($user_gallery_edit);

}
else {
  print drupal_render($user_gallery_new);
}

为什么我得到这个错误,即使我按预期打印完全

分享改善这个问题
 

一般来说,当你得到错误,导致错误的行是使用函数调用来传递其返回值作为另一个函数的参数,这意味着获取参数的函数是期望引用的,而用于获取作为参数传递的值不返回引用。

在你的情况下,render()被定义为render(&$element),但node_show()被定义为node_show($node, $message = FALSE),而不是&node_show($node, $message = FALSE)
对于drupal_render()也是如此,因为函数被定义为drupal_render(&$elements),并且期望引用作为其第一个参数。

通过引用传递所述,当函数需要引用作为参数时,可以传递给函数:

  • 变量
  • 的结果 new
  • 函数返回的引用

在具体情况下,由于您使用的是不返回引用的函数,因此只能使用变量存储结果node_show(),并将该变量传递给render()drupal_render()

请注意,在5.5.31(也可能是PHP 5.4)中,严格警告:只有通过引用传递的变量不会从以下代码返回,这样就test_array_print()可以获得参考。

function test_array_print(&$ref) {
  $ref[] = 10;
  print_r($ref);
}


function test_array() {
  return [3, 34];
}

test_array_print(test_array());

它打印以下内容。

Array
(
    [0] => 3
    [1] => 34
    [2] => 10
)

不过,看看有什么引用传递说:

不应通过引用传递其他表达式,结果未定义。例如,以下引用引用的例子无效:

<?php
  function foo(&$var)
  {
    $var++;
  }

  function bar() // Note the missing &
  {
    $a = 5;
    return $a;
  }

  foo(bar()); // Produces fatal error as of PHP 5.0.5, strict standards notice
              // as of PHP 5.1.1, and notice as of PHP 7.0.0

  foo($a = 5); // Expression, not variable
  foo(5); // Produces fatal error
?>
分享改善这个答案
 

保护社区♦ 4月3日在'16 5:56

感谢您对此问题的关注。因为它吸引了低质量或垃圾邮件的答案,必须删除,所以现在发布答案需要在这个网站10 声望协会奖金不算)。 

你想回答这些回答的问题之一吗?

不是你要找的答案?浏览其他有问题的问题 或问自己的问题


来自 https://drupal.stackexchange.com/questions/6322/strict-warning-only-variables-should-be-passed-by-re...

I get the following error:

Strict warning: Only variables should be passed by reference in include() (line 18 of /home/sites/dev/theparce/sites/all/themes/parce/block--block--3.tpl.php).

This is the block code which is causing that error.

if ($user_gallery) {
  print render(node_show($user_gallery));  // Line 18
  print drupal_render ($user_gallery_edit);

}
else {
  print drupal_render($user_gallery_new);
}

Why do I get that error, even if I get all printed as expected?

shareimprove this question
 

Generally speaking, when you get the error and the line causing the error is using a function call to pass its return value as parameter of another function, it means that the function getting the parameter is expecting a reference, while the function used to get the value to pass as parameter doesn't return a reference.

In your case, render() is defined as render(&$element), but node_show() is defined as node_show($node, $message = FALSE), not &node_show($node, $message = FALSE).
The same would be true for drupal_render(), since the function is defined as drupal_render(&$elements) and it expects a reference as its first argument.

As explained on Passing by Reference, when a function needs a reference as parameter, you can pass to the function:

  • Variables
  • The result of new
  • References returned from functions

In the specific case, since you are using a function that is not returning a reference, you can only use a variable to store the result of node_show(), and pass that variable to render() or drupal_render().

Notice that, in 5.5.31 (and maybe also PHP 5.4), the Strict warning: Only variables should be passed by reference is not returned from the following code, which works as if test_array_print() obtained a reference.

function test_array_print(&$ref) {
  $ref[] = 10;
  print_r($ref);
}


function test_array() {
  return [3, 34];
}

test_array_print(test_array());

It prints the following.

Array
(
    [0] => 3
    [1] => 34
    [2] => 10
)

Still, see what Passing by Reference says:

No other expressions should be passed by reference, as the result is undefined. For example, the following examples of passing by reference are invalid:

<?php
  function foo(&$var)
  {
    $var++;
  }

  function bar() // Note the missing &
  {
    $a = 5;
    return $a;
  }

  foo(bar()); // Produces fatal error as of PHP 5.0.5, strict standards notice
              // as of PHP 5.1.1, and notice as of PHP 7.0.0

  foo($a = 5); // Expression, not variable
  foo(5); // Produces fatal error
?>
shareimprove this answer
 

protected by Community Apr 3 '16 at 5:56

Thank you for your interest in this question. Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count). 

Would you like to answer one of these unanswered questions instead?

Not the answer you're looking for? Browse other questions tagged  or ask your own question

来自 https://drupal.stackexchange.com/questions/6322/strict-warning-only-variables-should-be-passed-by-re...
 


Strict warning : Only variables should be passed by reference dans views_page_title_pattern_alter()

Hello

I tried to use page_title in views (without any success for now) so I made a display in a view with the page_title option. Because I failed to make it work, I've deleted this display, and left my view has it was before my test.

Since then, when I go on pages made by views, I got this srtict warning :

Strict warning : Only variables should be passed by reference dans views_page_title_pattern_alter()(line 33 in /sites/all/modules/page_title/modules/views.page_title.inc).

Anyone has an idea from where it can come from ?
Maybe must I delete something in the DB ?

Thanks for your help.

Comments

nicholasThompson’s picture

 

I wonder what's being passed into that function which isn't a variable?!

anou’s picture

 

Is that suppose to mean that I can't pass some fixed string, must only use the tokens ?
...

nicholasThompson’s picture

 

You cant alter a fixed string - however you can alter a string assigned to a variable... eg:

Bad:

thingy('test');

function thingy(&$var) {
  $var = 'another test';
}

Good

$a = 'test';
thingy($a);

function thingy(&$var) {
  $var = 'another test';
}
amanire的照片

 

To fix the original problem in views.page_title.inc, replace line 33 with this:

// $h = array_shift(array_splice($h, count($args)-1, 1));
$hh = array_splice($h, count($args)-1, 1);
$h = array_shift($hh);

awm’s picture

 

subscribe

amanire的照片

 

I get the following error-message:

Strict warning: Only variables should be passed by reference in views_page_title_pattern_alter() (line 33 of C:\xampplite\htdocs\abt\sites\all\modules\page_title\modules\views.page_title.inc).

Please help me.
Thanks in advance

amanire的照片

 

I get the exact same error-message (#6), did you solve it?

a.milkovsky’s picture

 

Marshall_Kennard , thanks

amanire的照片

 

That is the same message as the original post and the solution is in post #4...

amanire的照片

 

Status:Active» Needs review
FileSize
0 bytes

Attached patch from comment #4

amanire的照片

 

Sorry empty patch; this should be right.

plach’s picture

 

Status:Needs review» Reviewed & tested by the community

Looks good and works as advertised.

amanire的照片

 

works! thanks for sharing :)

dercheffe’s picture

 

An update of the module which includes this patch would be great :)

nicholasThompson’s picture

 

Status:Reviewed & tested by the community» Fixed

This is fixed and committed into Dev branches for D6 and D7. Tagged release soon!

 

Status:Fixed» Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

来自  https://www.drupal.org/node/1206164

普通分类: