Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8779567
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T19:49:17+00:00 2026-06-13T19:49:17+00:00

So I have this parent class: class GenericHTMLElement { public function addElement(GenericHTMLElement $element) {}

  • 0

So I have this parent class:

class GenericHTMLElement
{
    public function addElement(GenericHTMLElement $element) {}
}

that is extended by these two classes

class ListViewItem extends GenericHTMLElement
{

}


class ListView extends GenericHTMLElement
{
    /**
     * @param ListViewItem $element
     * @throws WrongTypeException
     */
    public function addElement(GenericHTMLElement $element)
    {
        if (!$element instanceof ListViewItem)
        {
             throw new WrongTypeException("ListViewItem", $element);
        }
        parent::addElement($element);
    }
}

This works great. The problem is that it is not very clear that ListView::addElement() only accepts a ListViewItem object as argument.

Moreover, when generating documentation, it assumes $element should be of type GenericHTMLElement even with that javadoc comment.

However, changing the typehint triggers the StrictStandards warning.


EDIT: changed the questions a bit…

Q. Why is changing parameters in method overriding a violation of Strict Standards?
You can do that in other programming languages. And in PHP, you can do that in the constructor

Q. What are the implications of violating the Strict Standards in this case?
As I understand it, the strict warning appears to warn the programmer that there’s a possibility someone could read the signature of the parent class and assume it’s children behaves the same way. That could lead to a runtime error and halt in execution. But that is precisely what I’m trying to achieve.


EDIT:

Since it was asked in the comments, more details about this…

This is part of a Template Engine from Mobile Web Applications that uses JQuery Mobile at its core.

JQuery mobile has specific requirements regarding how to structure a “page”. jQueryMobile also uses specific attributes such as data-theme or data-position.

In order to manipulate the DOM of a page, you have to enforce that structure.

GenericHTMLElement represents a “generic” block of HTML (a div, a table, etc…).
A ListView is the jQueryMobile equivalent of a ul or ol. A ListView can only have a ListViewItem (li) as children. A listView, for instance, has a property named data-filter that enables or disables a search filter.

more info at http://jquerymobile.com/test/docs/api/data-attributes.html

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T19:49:18+00:00Added an answer on June 13, 2026 at 7:49 pm

    You already have defined the concrete type that the addElement method has to accept.

    If you now extend from that type and create a subtype that is more specific – or better said: different – , you are breaking that contract.

    PHP warns you about that with the strict standards warning.

    Either the listview element is generic and then it has to accept anything generic, too. Or it is something different but then it can not be generic in it’s own interface.

    So you should not disable the strict warning but think twice what you do there.

    It looks like that you want to be in conformance with the HTML DTD here that only allows certain elements within others. For example it is not allowed to place a <a> tag inside an <a> tag. However I find it highly non-productive if you try to break that down onto individual types and subtypes. You won’t finish your model – if even it can be properly expressed with PHP. However you should discuss that with your own first.

    Maybe the standard DOMDocument sheds some light on how HTML can be represented.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Supposed I have two classes like this: public class Parent { public string Id
I have a model that looks something like this: public abstract class Parent {
I have this entities: public class Parent: AllDependant { /*Properties goes here*/ } public
If I have a parent-child that defines some method .foo() like this: class Parent
Let's say I have something like this: abstract class Parent { protected function foobar($data)
I have this class as parent class: public partial class GetStuffResult { private int
I have this code that uses a template parent class A that has one
I have created this parent class class DBMysqli { private $mysqli; function __construct($Mysqli) {
I am using this jQuery function to find the parent element with class name
I have a base class Parent like this: using System; using System.Collections.Generic; using System.Text;

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.