1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

how extends class

Discussion in 'XenForo Development Discussions' started by Hugilore111, Oct 3, 2015.

  1. Hugilore111

    Hugilore111 Member

    hello!
    how extends class
    example:
    Code:
    <?php
    class Display_Model_Post extends XFCP_Display_Model_Post
    {
        public function preparePost(array $post, array $thread,array $forum, array $nodePermissions = null, array $viewingUser = null)
        {
          
                parent::preparePost(array $post, array $thread,array $forum, array $nodePermissions = null, array $viewingUser = null);
       
        }
      
       
      
    }
    I receive an error
    Parse error: syntax error, unexpected '$post' (T_VARIABLE), expecting '(' in C:\xampp\htdocs\xd\library\Display\Model\Post.php on line 7
     
  2. Chris D

    Chris D XenForo Developer Staff Member

    The call to the parent shouldn't include the variable types or the default values.
     
    Hugilore111 likes this.
  3. Hugilore111

    Hugilore111 Member

    Thanks Chris
    Wrong again.
    what am I doing wrong?
    Server Error
    Argument 1 passed to XenForo_Model_Post:preparePost() must be of the type array, none given, called in C:\xampp\htdocs\xd\library\Display\Model\Post.php on line 7 and defined
     
  4. thedude

    thedude Well-Known Member

    You didn't actually post what your edited call now looks like. But this is what it should look like:
    Code:
    parent::preparePost($post, $thread, $forum, $nodePermissions, $viewingUser);
    
    and one thing you're overlooking is that XenForo_Model_Post::preparePost returns a value. So depending on what you're trying to do exactly, you might want to do this:

    Code:
    $retVal = parent::preparePost($post, $thread, $forum, $nodePermissions, $viewingUser);
    *do my own stuff here*
    return $retVal;
    
    If you don't, whatever function is calling preparePost won't get the expected return from it.
     
    Hugilore111 likes this.
  5. Chris D

    Chris D XenForo Developer Staff Member

    Would need to see the current code.
     

Share This Page