call new login page func imloginerror 怎么办

标题: 签名: 最远的你是我最近的爱截止抓取时间: 115 | 积分:21965 | 排名: | 原创: 219 | 转载: 1125 | 译文: 13 | 评论: 75 | 访问量: 1928144
此博客下共有: 1317 篇文章.
序号标题序号标题
标题: 签名: 截止抓取时间: 104 | 积分:20826 | 排名: | 原创: 331 | 转载: 5 | 译文: 3 | 评论: 1793 | 访问量: 1940875
此博客下共有: 338 篇文章.
序号标题序号标题
标题: 签名: 与其临渊羡鱼,不如退而结网。截止抓取时间: 437 | 积分:11113 | 排名: | 原创: 170 | 转载: 1 | 译文: 0 | 评论: 4568 | 访问量: 240785
此博客下共有: 171 篇文章.
序号标题序号标题
标题: 签名: 截止抓取时间: 703 | 积分:43938 | 排名: | 原创: 431 | 转载: 4678 | 译文: 22 | 评论: 1322 | 访问量: 3224935
此博客下共有: 5160 篇文章.
序号标题序号标题
标题: 签名: 俯首甘为孺子牛截止抓取时间: 239 | 积分:16624 | 排名: | 原创: 305 | 转载: 5 | 译文: 0 | 评论: 890 | 访问量: 1371269
此博客下共有: 308 篇文章.
序号标题序号标题
标题: 签名: 截止抓取时间: 629 | 积分:7346 | 排名: | 原创: 65 | 转载: 16 | 译文: 0 | 评论: 968 | 访问量: 582210
此博客下共有: 81 篇文章.
序号标题序号标题
标题: 签名: 龙铭洪这是关注互联网的各种技术,电脑,编程,设计,开发,系统,数据库,管理,黑客截止抓取时间: 749 | 积分:4803 | 排名: | 原创: 161 | 转载: 1 | 译文: 20 | 评论: 214 | 访问量: 424219
此博客下共有: 186 篇文章.
序号标题序号标题call new login page func error refresh怎么解决_百度知道
call new login page func error refresh怎么解决
提问者采纳
call new login page func error refresh的中文翻译 call new login page func error refresh 调用函数误差刷新新的登录页面
来自团队:
其他类似问题
为您推荐:
其他1条回答
呼出新登录页面功能出错,刷新
等待您来回答
下载知道APP
随时随地咨询
出门在外也不愁Keyboard Shortcuts?
Next menu item
Previous menu item
Previous man page
Next man page
Scroll to bottom
Scroll to top
Goto homepage
Goto search(current page)
Focus search box
Change language:
Brazilian Portuguese
Chinese (Simplified)
call_user_func_array
call_user_func_array & Call a callback with an array of parameters
Description
call_user_func_array
, array $param_arr
Parameters
to be called.
The parameters to be passed to the callback, as an indexed array.
Return Values
Returns the return value of the callback, or FALSE on error.
Example #1 call_user_func_array() example
&?phpfunction&foobar($arg,&$arg2)&{&&&&echo&__FUNCTION__,&"&got&$arg&and&$arg2\n";}class&foo&{&&&&function&bar($arg,&$arg2)&{&&&&&&&&echo&__METHOD__,&"&got&$arg&and&$arg2\n";&&&&}}//&Call&the&foobar()&function&with&2&argumentscall_user_func_array("foobar",&array("one",&"two"));//&Call&the&$foo-&bar()&method&with&2&arguments$foo&=&new&foo;call_user_func_array(array($foo,&"bar"),&array("three",&"four"));?&
The above example will output
something similar to:
foobar got one and two
foo::bar got three and four
Example #2 call_user_func_array() using namespace name
&?phpnamespace&Foobar;class&Foo&{&&&&static&public&function&test($name)&{&&&&&&&&print&"Hello&{$name}!\n";&&&&}}//&As&of&PHP&5.3.0call_user_func_array(__NAMESPACE__&.'\Foo::test',&array('Hannes'));//&As&of&PHP&5.3.0call_user_func_array(array(__NAMESPACE__&.'\Foo',&'test'),&array('Philip'));?&
The above example will output
something similar to:
Hello Hannes!
Hello Philip!
Example #3 Using lambda function
&?php$func&=&function($arg1,&$arg2)&{&&&&return&$arg1&*&$arg2;};var_dump(call_user_func_array($func,&array(2,&4)));&/*&As&of&PHP&5.3.0&*/?&
The above example will output:
Before PHP 5.4, referenced variables in param_arr
are passed to the function by reference, regardless of whether the function
expects the respective parameter to be passed by reference. This form of
call-time pass by reference does not emit a deprecation notice, but it is
nonetheless deprecated, and has been removed in PHP 5.4.
Furthermore, this does not apply to internal functions, for which
the function signature is honored. Passing by value when the function
expects a parameter by reference results in a warning and having
return FALSE (there is, however, an
exception for passed values with reference count = 1, such as in literals,
as these can be turned into references without ill effects — but also
without writes to that value having any effect —; do not rely
in this behavior, though, as the reference count is an implementation
detail and the soundness of this behavior is questionable).
Note: Callbacks registered
with functions such as
and call_user_func_array() will not be
called if there is an uncaught exception thrown in a previous callback.
- Call the callback given by the first parameter
information about the
- Invokes function args
- Invoke args
Just hope this note helps someone (I killed the whole day on issue).
If you use something like this in PHP & 5.3:
&?php call_user_func_array(array($this, 'parent::func'), $args); ?&
Such a script will cause segmentation fault in your webserver.
In 5.3 you should write it:
&?php call_user_func_array('parent::func', $args); ?&
Please note, that when calling call_user_func_array() to redirect parameters between inherited classes, you should not use $this, because $this always refers to the class which has been instantiated. The following code even seems to crash PHP (PHP does not report error but the process simply terminates), because the the parameters are redirected only one level up (to class foo_bar2):&?php& & class foo_bar1& & {& & & & public function __construct()& & & & {& & & & & & echo __CLASS__ . PHP_EOL;& & & & & & if (func_num_args() & 0)& & & & & & {& & & & & & & & $constructorArgs = func_get_args();& & & & & & & & call_user_func_array(array($this, 'parent::__construct'), $constructorArgs);& & & & & & }& & & & & & else& & & & & & {& & & & & & & & parent::__construct();& & & & & & }& & & & }& & }& & class foo_bar2 extends foo_bar1& & {& & & & public function __construct()& & & & {& & & & & & echo __CLASS__ . PHP_EOL;& & & & & & if (func_num_args() & 0)& & & & & & {& & & & & & & & $constructorArgs = func_get_args();& & & & & & & & call_user_func_array(array($this, 'parent::__construct'), $constructorArgs);& & & & & & }& & & & & & else& & & & & & {& & & & & & & & parent::__construct();& & & & & & }& & & & }& & }& & class foo_bar3 extends foo_bar2& & {& & & & public function __construct()& & & & {& & & & & & echo __CLASS__ . PHP_EOL;& & & & & & if (func_num_args() & 0)& & & & & & {& & & & & & & & $constructorArgs = func_get_args();& & & & & & & & call_user_func_array(array($this, 'parent::__construct'), $constructorArgs);& & & & & & }& & & & & & else& & & & & & {& & & & & & & & parent::__construct();& & & & & & }& & & & }& & }& & $f = new foo_bar3("abc");?&Instead, use the direct name of the class as string or, better, the magic constant __CLASS__ in call_user_func_array(), like:& & call_user_func_array(array(__CLASS__, 'parent::__construct'), $constructorArgs);Then the parameters will be correctly redirected to the lowest base class.
$param_arr may be empty, though it can't be null.&?phpfunction foo( $first = 'default1', $second = 'default2' ) {& & echo "first: '$first', second: '$second'\n";}call_user_func_array( 'foo', array( 'one', 'two' ) );call_user_func_array( 'foo', array( 'only one' ) );call_user_func_array( 'foo', array() );call_user_func_array( 'foo', null );?&Output:first: 'one', second: 'two'first: 'only one', second: 'default2'first: 'default1', second: 'default2'/* error message or nothing printed depending on version */
As of PHP 5.6 you can utilize argument unpacking as an alternative to call_user_func_array, and is often 3 to 4 times faster.&?phpfunction foo ($a, $b) {& && return $a + $b;}$func = 'foo';$values = array(1, 2);call_user_func_array($func, $values); $func(...$values);?&Benchmarks from cufa&& with 0 args took 0.08switch with 0 args took 0.82unpack with 0 args took 0.26cufa&& with 5 args took 0.55switch with 5 args took 0.96unpack with 5 args took 0.19cufa&& with 100 args took 5.9switch with 100 args took 5.unpack with 100 args took 1.1
For anyone looking for the means to test for the first parameter before passing to this function, look at the is_callable () variable handler.&?php$handler = array( 'MyClass', 'MyMethod');$params = array(1,2,3,4);if ( is_callable($handler) ) { call_user_func_array( $handler , $params ); }?&
Those having the passing by reference issue can use this simple hack.
I?m really not sure WHY this works, but it does, and it does not make use of EVAL or other questionable functions.
&?php
& & function executeHook($name, $type='hooks'){
& & & & $args = func_get_args();
& & & & array_shift($args);
& & & & array_shift($args);
& & & & $Args = array();
& & & & foreach($args as $k =& &$arg){
& & & & & & $Args[$k] = &$arg;
& & & & }
& & & & $hooks = &$this-&$type;
& & & & if(!isset($hooks[$name])) return false;
& & & & $hook = $hooks[$name];
& & & & call_user_func_array($hook, $Args);
& & }
?&
All it?s doing is copying the args ($args) into a new array ($Args) by reference, which i would think would be identical to the original array in every way (that matters).
Note the code here is an example of usage. The actual hack is denoted by comments.
If someone knows a better alternative, by all means, i would love to see it.
For those wishing to implement call-by-name functionality in PHP, such as implemented e.g. in DB apis, here's a quick-n-dirty version for PHP 5 and up&?phpfunction call_user_func_named($function, $params){& & if (!function_exists($function))& & {& & & & trigger_error('call to unexisting function '.$function, E_USER_ERROR);& & & & return NULL;& & }& & $reflect = new ReflectionFunction($function);& & $real_params = array();& & foreach ($reflect-&getParameters() as $i =& $param)& & {& & & & $pname = $param-&getName();& & & & if ($param-&isPassedByReference())& & & & {& & & & & & }& & & & if (array_key_exists($pname, $params))& & & & {& & & & & & $real_params[] = $params[$pname];& & & & }& & & & else if ($param-&isDefaultValueAvailable()) {& & & & & & $real_params[] = $param-&getDefaultValue();& & & & }& & & & else& & & & {& & & & & & trigger_error(sprintf('call to %s missing parameter nr. %d', $function, $i+1), E_USER_ERROR);& & & & & & return NULL;& & & & }& & }& & return call_user_func_array($function, $real_params);}?&
Just a heads up, the second parameter MUST be an array if it's specified,& but that doesn't seem to be enforced until ~5.3.I just pulled my hair out with an old installation of CakePHP because it was passing NULL instead of an empty array.
call_user_func_array can pass parameters as reference:
&?php
call_user_func_array(array(&$obj,$method),array(&$arg1,$arg2,$arg3))
?&
Use it as work-around for "Call-time pass-by-reference has been deprecated".
Many people have wondered how to effectively implement dispatch tables in PHP.& Here's my answer to that (if you'll forgive my creative flair):&?phpdefine( "YOUR_MOTHER",& 1 );define( "YOUR_FATHER",& 2 );define( "YOUR_BROTHER", 3 );define( "YOUR_SISTER",& 4 );class MyFamily{& & static $dispatch = array( YOUR_MOTHER =& "Mom", YOUR_FATHER =& "GetPrisonInmate", YOUR_BROTHER =& "ReplaceName", YOUR_SISTER =& "LazyGirl" );& & static $args = array( YOUR_MOTHER =& array(), YOUR_FATHER =& array( "", TRUE ), YOUR_BROTHER =& array(), YOUR_SISTER =& array() );& & & & function GetDispatch( $fromwhere )& & {& & & & return call_user_func_array( array( self, self::$dispatch[$fromwhere] ), self::$args[$fromwhere] );& & }& & & & function Mom()& & {& & & & return "Mommy loves you!";& & }& & & & function GetPrisonInmate( $PrisonerID, $GoodBehavior )& & {& & & & if ( $GoodBehavior )& & & & {& & & & & & $parole = "APPROVED";& & & & }& & & & else& & & & {& & & & & & $parole = "DENIED";& & & & }& & & & & & & & return "Your father (#$PrisonerID) has $remaining years left in his sentence.& His most recent parole application has been:& $parole";& & }& & & & function ReplaceName()& & {& & & & return "Her name is Sally now.";& & }& & & & function LazyGirl()& & {& & & & print "Your sister needs to get out more....";& & & & & & & & die( "Nah, I'm too tired." );& & }}print "Status on family member: " . MyFamily::GetDispatch( YOUR_FATHER );?&
It appears that when PHP executes something like:$a = array(1,2,3);$b =& $a[1];both $b and $a[1] are converted into references to a common value -- makes sense until you transfer that to a call_user_func:call_user_func_array('foo', $a);suddenly, inside foo, the second parameter is passed by reference!And you can't call this wrong, only another subtly of references.Note it appears that ksort($a) will remove the reference as well as put the elements in key order so you (probably) get what you expect. (see below on the use of a foreach ($a as &v).)
There's a possibility that call_user_func_array(), call_user_func(), and Exception::getTrace() will cause a trace entry to not have the 'file' or 'line' elements.Dustin Oprea
Regarding the comments below about calling parent constructors:
PHP5 with E_STRICT no longer allows calls as below:
&?php
call_user_func_array(array('parent', '__construct'), $args);
?&
It gives an error because you are trying to call a nonstatic function as if it was static. The correct syntax is
&?php
call_user_func_array(array($this, 'parent::__construct'), $args);
?&
Just an extra for the post of amer at o2 dot pl:If you need to call the PARENT method:call_user_func_array(array('parent', 'method'), $args);With that, if you need to call a constructor and/or add some extra code to the instantiation process:&?phpfunction __construct() {& & $args = func_get_args();& & call_user_func_array(array('parent', '__construct'), $args);& & }?&Note that your constructor pass all the arguments to the parent constructor and it doesn't matter how many arguments you pass.This is pretty useful for constructors with a variable number of arguments.
I've found the solution to resolve my need while writing the str_replace function for processing the multi array as first two arguments of str_replace built-in function(although its pass each array of argument 1 & 2)&?phpfunction p_str_replace($argFind, $agrReplace, $theString) {& $needle_replace = $theString; array_walk($argFind, function($val, $key) use(&$needle_replace, $agrReplace) {& & $needle_replace = call_user_func_array('str_replace', array($val, $agrReplace[$key], $needle_replace));& });& return $needle_replace;}$the_str = array(& 'coa' =& ':col: :op1: :val: AND :col: :op2: :val:');$ope = array('&=', '&=');$colsdata = array('date_start', '');echo p_str_replace(array(& & & & & array(':col:', ':val:'),& & & & & array(':op1:', ':op2:')& & & & ), array(& & & & & & $colsdata,& & & & & & $ope& & & & ), $the_str['coa']);echo '-------------------------------' . "\n";$complex = '(:col: :op1: :val: AND :col: :op2: :val:) AND (:col2: :op1: :val2: AND :col2: :op1: :val2:)';echo p_str_replace(array(& array(':col:', ':val:'),& array(':col2:', ':val2:'),& array(':op1:', ':op2:')), array(& array('date_start', ''),& array('date_end', ''),& array('&', '&')), $complex);?&Sorry about my bad English :)Hope this help someone.
PLS notice that "patripaq at hotmail dot com" 's code will be valid if B EXTENDS A...&?phpclass B extends A{...} ?&there&&"What I wanted to do is create an object that can manage any number and any kind of parameters."BUT IT IS NOT A POINT AT ALLIf you need to call just function with parameters:call_user_func_array('Foo',$args);If you need to call CLASS method (NOT object):call_user_func_array(array('class', 'Foo'),$args); If you need to call OBJECT method:call_user_func_array(array(&$Object, 'Foo'),$args);If you need to call method of object of object:call_user_func_array(array(&$Object-&Object, 'Foo'),$args);If you need to call object method from within the very same object (NOT CLASS!):call_user_func_array(array(&$this, 'Foo'),args);The call_user_func_array ITSELF can manage any number and any kind of parameters. It can handle ANY FUNCTION too as it is defined and that maybe partipaq wanted to manage. What You actually need is object composition not inheritance. Make an instance from arguments. &?php...class B{&& function __construct() {& & & $args = func_get_args(); $this-&OBJ = new A($args);& & & call_user_func_array(array(&$this-&OBJ, 'A'), $args );&& }}?&Then there can be any number and any type of created object B parameters
For those of you that have to consider performance: it takes about 3 times as long to call the function this way than via a straight statement, so whenever it is feasible to avoid this method it's a wise idea to do so.Note that eval() is about 10 times slower than a straight statement to call a function with arguments, so this is definitely a better option than using eval() even if you only consider performance.
call_user_func_array() is nifty for calling PHP functions which use variable argument length. For example:
&?php
$array = array(
array("foo", "bar"),
array("bat", "rat"),
);
$values = call_user_func_array("array_merge", $array);
var_dump($values);
?&
/* output:
array(4) {
& [0]=&
& string(3) "foo"
& [1]=&
& string(3) "bar"
& [2]=&
& string(3) "bat"
& [3]=&
& string(3) "rat"
}
*/
The neat feature is that $array could have any number of arrays inside it.
&?phpClass Delegate{& & private $arrInstances = array();& & & & protected function addObject( $oElement )& & {& & & & $this-&arrInstances[] = $oElement;& & }& & & & & & public function __call( $strMethod, $arrParams )& & {& & & & foreach( $this-&arrInstances as $oElement )& & & & {& & & & & & $strClass = get_class( $oElement );& & & & & & $arrMethods = get_class_methods( $strClass );& & & & & & if( in_array( $strMethod , $arrMethods ) ) & & & & & & {& & & & & & & & $arrCaller = Array( $strClass , $strMethod );& & & & & & & & return call_user_func_array( $arrCaller, $arrParams );& & & & & & }& & & & }& & & & throw new Exception( " Method " . $strMethod . " not exist in this class " . get_class( $this ) . "." );& & }}class Log{& & public function sayHi()& & {& & & & print "hi!" . "&br/&\n";& & }& & & & public function sayMyName()& & {& & & & print "log" . "&br/&\n";& & }}class Other{& & public function sayHello()& & {& & & & print "hello there!" . "&br/&\n";& & }& & & & public function sayMyName()& & {& & & & print "other" . "&br/&\n";& & }}class Example extends Delegate{& & public function __construct()& & {& & & & $this-&addObject( new Log() );& & & & $this-&addObject( new Other() );& & }}$oExample = new Example();$oExample-&sayHi();$oExample-&sayHello();$oExample-&sayMyName();?&
Be aware the call_user_func_array always returns by value, as demonstrated here...&?php& & & & function &foo(&$a)& & {& & & return $a;& & }& & & & $b = 2;& & $c =& call_user_func_array('foo', array(&$b));& & $c++;& & echo $b . ' ' . $c;& & ?&outputs "2 3", rather than the expected "3 3".Here is a function you can use in place of call_user_func_array which returns a reference to the result of the function call. &?php& & function &ref_call_user_func_array($callable, $args)& & {& & & & if(is_scalar($callable))& & & & {& & & & & & $call = $callable;& & & & }& & & & else& & & & {& & & & & & if(is_object($callable[0]))& & & & & & {& & & & & & & & $call = "\$callable[0]-&{$callable[1]}";& & & & & & }& & & & & & else& & & & & & {& & & & & & & & $call = "{$callable[0]}::{$callable[1]}";& & & & & & }& & & & }& & & & & & & & $argumentString = array();& & & & $argumentKeys = array_keys($args);& & & & foreach($argumentKeys as $argK)& & & & {& & & & & & $argumentString[] = "\$args[$argumentKeys[$argK]]";& & & & }& & & & $argumentString = implode($argumentString, ', ');& & & & eval("\$result =& {$call}({$argumentString});");& & & & return $result;& & }?&
If you are using PHP & 5.3 and want to call the parent class' __construct() with a variable parameter list, use this:
&?php
public function __construct()
{
& & $vArgs = func_get_args(); call_user_func_array(array('parent', '__construct'), $vArgs);
}
?&
This function is relatively slow (as of PHP 5.3.3) and if you are calling a method with a known number of parameters it is much faster to call it this way:
$class-&{$method}($param1, $param2);
call_user_func_array (array($class, $method), array($param1, $param2));
But if you don't know how many parameters...
The wrapper function below is slightly faster, but the problem now is that you are making two function calls.& One to the wrapper and one to the function.
However, If you are able to take this code out of the function and use it inline it is nearly twice as fast (in most cases) as calling call_user_func_array natively.
&?php
function wrap_call_user_func_array($c, $a, $p) {
& & switch(count($p)) {
& & & & case 0: $c-&{$a}();
& & & & case 1: $c-&{$a}($p[0]);
& & & & case 2: $c-&{$a}($p[0], $p[1]);
& & & & case 3: $c-&{$a}($p[0], $p[1], $p[2]);
& & & & case 4: $c-&{$a}($p[0], $p[1], $p[2], $p[3]);
& & & & case 5: $c-&{$a}($p[0], $p[1], $p[2], $p[3], $p[4]);
& & & & default: call_user_func_array(array($c, $a), $p);&
& & }
}
?&
&?php& return call_user_func_array(& & array(new ReflectionClass($className), 'newInstance'),& & $functionParameters& );?&Look here:
Note that, despite the name, this does work on builtin functions (and object methods with the array(&$obj, $method) syntax), not just user-defined functions and methods.
Here is another version of createObjArray() function written here earlier by taylor.Believing that using 'eval()' is at least "dirty", I came to the following solution (with a help of panchous - at phpclub dot ru forums ). This solution utilizes the new Reflection API.&?phpfunction & createObjArray($type, $args = array()) {& & $reflection = new ReflectionClass($type);& & $output& && = call_user_func_array(array(&$reflection, 'newInstance'), $args);& & return $output;}?&
I came up with a better solution to the problem that I solve below with createObjArray that maintains parameter type:&?phpfunction createObjArray($type,$args=array()) {& && $paramstr = '';& && for ($i = 0; $i & count($args); $i++) {& & & & && $paramstr .= '$args['.$i.'],';& && }& && $paramstr = rtrim($paramstr,',');& && return eval("return new $type($paramstr);");}?&Would be good to add error checking, but it works.
If you are thinking of using call_user_func_array to instantiate an object (see comments below using Reflection) then since v5.1.3 you can use the Reflection::newInstanceArgs() method.
$args = array('a', 'b');
$className = 'myCommand';
$reflectionObj = new ReflectionClass($className);
$command = $reflectionObj-&newInstanceArgs($args);
I just noticed that when you use this function with parameters that need to be passed by reference it will not work.&?phpfunction refFunc(&$var){& $var .= 'bar';}$var = 'foo';?&call_user_func_array('refFunc', array($var));echo $will output 'foo' and not& 'foobar'. Witch is logical since you are declaring a new variable with array($var) however not so obvious.

我要回帖

更多关于 callfunc 的文章

 

随机推荐