How to simulate non existing method error in __call?

You can trigger PHP errors manually using trigger_error:

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


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 .
Privacy Policy - Copyrights Notice - Feedback - Report Violation - RSS 2017 © All Rights Reserved .