I am getting error "Function create_function() is deprecated in..."
From searching for how to fix, I found out I am supposed to use anonymous function. But I don't know the syntax. Can someone please help?
This is the function in question.
static function CreateTplFunc($parsed_tpl) {
return create_function('$f,$e=null', "return ($parsed_tpl);");
}
Thanks!
Related
When I am trying to compile the following code:
var post = iPostService.GetAll().Select(x => (x.Title, x.Author));
I get the compiler error: 'An expression tree may not contain a tuple literal.'
So I also tried this:
var post = iPostService.GetAll().
Select(x => new ValueTuple<string, string>(x.Title, x.Author))
The result is runtime error:'Cannot resolve method Void .ctor(System.String, System.String) because the declaring type of the method handle System.ValueTuple`2[T1,T2] is generic. Explicitly provide the declaring type to GetMethodFromHandle.'
I googled to find out the solution to this problem but nothing really helpful.
Any help really appreciated.
Thanks
It works for me, create a tuple first and convert it to a ValueTuple:
var post = iPostService.GetAll().
Select(x => new Tuple<string, string>(x.Title, x.Author).ToValueTuple())
Finally, I found out what wrong with my code:
I am using deferred execution so data won't load from the database when the constructor executed.
The solution is to add conversion operators before creating instance command.
Hope it works with your code.
How do I replace an assertion error message? If I call $this->assertTrue(false, 'message'), it will display both the string "message" and also another message stating that false is not true. How do I get it to only output the message that I chose? Is this even possible?
code-crutch which comes to my mind when I faced the same problem:
public function assertTrue($condition, $message = '')
{
if (!$condition) $this->fail($message);
}
With PHPUnit 6 you must have got one assertion at least, so i suggest a little edited #avolkov answer:
public function assertTrue($condition, $message = '')
{
if (!$condition){
$this->fail($message); //This will cause test fail with your message
}
else{
$this->anything(); //This will eliminate error which says that your test doesn't have assertion
}
}
It's not possible.
Why would you want to do so? Never encountered a case in which the default message is not helpful in any way. The custom message should add information, not replace the default one.
Object.class.getMethod(methodName, Object.class);
is not getting executed by bsh.Interpreter and throwing exceptions
Typed variable declaration : reflection error: bsh.ReflectError: Method getMethod( java.lang.String, java.lang.Class ) not found in class'java.lang.Class'
Any idea how to fix this ?
Thanks in advance.
Beanshell doesn't support variable parameters, so you need to put it in an array as per older versions of the Java language.
Object.class.getMethod("equals", new Class[] { Object.class } );
Edit
The basic question here is "when does the $op parameter get defined as 'search'"?
I am trying to create a custom search in an implementation of hook_search(). I have been looking through the Drupal documentation for the method here: http://api.drupal.org/api/drupal/developer--hooks--core.php/function/hook_search/6
I know the method is running because I can slip a die('killed inside of implementation of hook_search()') into the top of the function and see the output.
In the following code, the script is never killed so that I can see the output search caught inside of my_search(). This leads me to believe that the 'search' case of the switch statement is never firing. Does anybody know where I might go from here?
/**
* Implementation of hook_search()
*/
function my_search($op = 'search', $keys = NULL) {
switch($op)
{
case 'search':
die('search caught inside of my_search()');
break;
}
}
First things first.
Assuming your module is called 'my', try to go to URL /search/my/whatever - probably you will see access forbidden page (assuming you do not have anything more in your code besides what you have pasted in your question).
That's because you do not return anything when search module calls your hook with $op = 'name' (see _search_menu() in search.module). You need to return "a translated name defining the type of items that are searched for with this module ('content', 'users', ...)" - see http://api.drupal.org/api/drupal/developer--hooks--core.php/function/hook_search/6 And access forbidden gone.
Once this is done, search will call your hook again (actually, there are quite a few calls, you can for example drupal_set_message($op) in your hook to see them all), and one of those calls will be with $op = "search" as well (coming from search_data() in search.module).
So I have a class where I instantiate a variable callback like so:
public var callback:Function;
So far so good. Now, I want to add an event listener to this class and test for existence of the callback. I'm doing like so:
this.addEventListener(MouseEvent.MOUSE_OVER, function(event:MouseEvent) : void {
if (callback) {
// do some things
}
});
This works great, doesn't throw any errors, but everywhere I test for callback I get the following warning:
3553: Function value used where type Boolean was expected.
Possibly the parentheses () are missing after this function reference.
That bugged me, so I tried to get rid of the warning by testing for null and undefined. Those caused errors. I can't instantiate a Function as null, either.
I know, I know, real programmers only care about errors, not warnings. I will survive if this situation is not resolved. But it bothers me! :) Am I just being neurotic, or is there actually some way to test whether a real Function has been created without the IDE bitching about it?
Similar to using typeof:
if(callback is Function){
}
I believe should evaluate to true if the function exists and is a function and false if it is null or is not a function. (although if that doesn't work try if(callback && callback is function){}
if( !(callback == null)){
// do something
}
There's already an answer that works, but I thought I'd mention that you can also stop the warning from occurring by explicitly casting the result to a Boolean.
if (Boolean(callback)) {
// do something
}
Have you tried:
if (typeof callback == "function") {
// do some things
}
?
http://www.adobe.com/livedocs/flash/9.0/ActionScriptLangRefV3/operators.html#typeof