codingdir logo sitemap sitemap |
Home
PHP
C#
C++
ANDROID
JAVA
JAVASCRIPT
PYTHON

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);

See http://php.net/manual/en/function.trigger-error.php

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().

Eg

private void mySharedMethod (){
 //implementation
}

public void onHomeClicked (View v){
  mySharedMethod();
}

public boolean onOptionsItemSelected (MenuItem item){
  switch (item.getItemId ()){
    case android.R.id.home:
       mySharedMethod();
       return true;
    default:
       return super.onOptionsItemSelected (item);
  }
}
def some
  method_name = (self.public_methods - Object.instance_methods).sample
  public_send(method_name)
end

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:

$this->{$PageName}();

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).

Comments


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 © codingdir.com All Rights Reserved .