codingdir logo sitemap sitemap |

How to simulate non existing method error in __call?

By : , Category : php

You can trigger PHP errors manually using trigger_error:

trigger_error('Call to undefined method '.__CLASS__.'::'.$name.'()', E_USER_ERROR);


ReLated :

You have no MenuItem, whatever logic onOptionsItemSelected() would contain would fail (assuming there are multiple options).

Since you seem to have a need for shared code, move that piece of logic to its own method, then call that method from both onHomeClicked() and onOptionsItemSelected().


private void mySharedMethod (){

public void onHomeClicked (View v){

public boolean onOptionsItemSelected (MenuItem item){
  switch (item.getItemId ()){
       return true;
       return super.onOptionsItemSelected (item);
def some
  method_name = (self.public_methods - Object.instance_methods).sample

That will probably do it for you :)

Take a look at call_user_func() and call_user_func_array() functions, they can accomplish this in a more meaningful way:

call_user_func(array($this, $PageName));

By the way, this would do the trick with variable-variable:


Constructors can't be async, but there are some ways to work around that.

Since you're using inheritance, you can't use the Factory Pattern from the above article directly, but you can combine the Factory Pattern for the derived class with a version of the The Asynchronous Initialization Pattern for the base class:

class BaseStorage
    protected BaseStorage(IStorageItem storageItem)
        this.Name = storageItem.Name;
        this.CreationDate = storageItem.DateCreated.ToString();

        Initialization = setModifiedDateAndOwner(storageItem);

    protected Task Initialization { get; private set; }

    private async Task setModifiedDateAndOwner(IStorageItem storageItem)

class Document : BaseStorage
    private Document(IStorageFile storageFile)
        : base(storageFile)
    { }

    public static async Task<Document> Create(IStorageFile storageFile)
        var result = new Document(storageFile);

        await result.Initialization;

        return result;

This way, you have to be careful when implementing Document and other classes that inherit from BaseStorage, but you can only use those classes correctly (you have to await the Task to get the created instance).


Message :
Login to Add Your Comments .
How to disable registered OpenCL platforms on Windows?
Is Observable broken in Angular 2 Beta 3?
Cross-thread operation not valid when using Invoke
How to pass an IEnumerable or queryable list of properties from Controller to View
Finding numbers after a certain keyword using Python
Pocketsphinx recognizes random phrases in a silence
Passing non-thread-safe objects through thread-safe containers
React scroll nav
BizTalk WCF-BasicHttp Adapter does not allow Empty string for Service Certificate Props
Why property ''cause" of Exception is repeating forever?
Privacy Policy 2017 © All Rights Reserved .