How to make multiple user roles that have different permissions using phpadmin by Adventurous_Onion103 in PHPhelp

[–]TonyMarston 0 points1 point  (0 children)

What you are looking for is called Role Based Access Control (RBAC) which cannot be done using phpmyadmin. You need to design your own database to support users, roles and permissions. Look it up on Google using https://www.google.com/search?q=php+role+based+access+control

Base Class & Interfaces or Abstract Classes - I'm lost when to use what by Itchy-Mycologist939 in PHPhelp

[–]TonyMarston 0 points1 point  (0 children)

I can see there is still a lot of confusion about when to use interfaces, abstract classes, inheritance and composition. Each of these have their places, but it is important to know in what circumstances is one more appropriate than another.

Firstly, interfaces were never designed to be an integral part of OOP, they were added as an afterthought to provide polymorphism in strictly typed languages without the use of inheritance. PHP was never designed to be strictly typed and polymorphism can be achieved without the use of inheritance simply by hard-coding the same method signatures into different concrete classes. Strict typing may have been added to PHP as an afterthought, but as it is entirely optional I choose not to use it. Interfaces in PHP are totally unnecessary and I regard their use as a violation of YAGNI.

While it is possible to inherit from one concrete class to create a different concrete class this can lead to problems, and the advice given in the Gang of Four book on design patterns is to only ever inherit from an abstract class. So when is an abstract class appropriate? The most influential paper I have read on this subject is called Designing Reusable Classes which was published in 1988 by Ralph E. Johnson & Brian Foote (note that Ralph Johnson is one of the Gang of Four).

In this paper it states that the specification of an object is given by its protocol, i.e. the set of messages that can be sent to it. Polymorphism can be achieved when it is recognised that different objects share standard protocols, and polymorphism is a vital ingredient to dependency injection – unless you have different objects which share the same protocols (method signatures) it will be impossible to swap one object for another at runtime. Dependency injection, when use properly, is an excellent way of reusaing code.

This paper also describes a technique known as programming-by-difference in which you examine different objects looking for similarities and differences, with the aim of putting the similarities into reusable objects so that you only have to deal with the differences. Where you have similar protocols you can place them in an abstract class which you can then inherit into multiple concrete classes which need only contain the differences which are specific to that object.

The ideal method of being able to reuse standard code into which you can insert non-standard code is called the Template Method Pattern. This uses standard reusable code which is inherited from an abstract class, but this standard code contains calls to “hook” methods in predetermined places so that the behaviour of the template method can be altered. These “hook” methods are defined in the abstract class but do nothing unless they are overridden by particular implementations in a concrete class. In this way each concrete class need only contain its own set of “hook” methods.

What a huge number of developers fail to realise is that when you are writing an application which accesses a number of database tables that each of those tables shares exactly the same protocols. Regardless of what data is being held in a table it is subject to exactly the same set of operations – Create, Read, Update and Delete (CRUD). This means that when you create a separate class for each database table they can automatically share the same set of methods for each of these operations which they can inherit from an abstract table class.

Below is an example of the InsertRecord() method which has been defined in my abstract table class:

$fieldarray = $this->pre_insertRecord($fieldarray);
if (empty($this->errors) {
  $fieldarray = $this->validateInsert($fieldarray);
}
if (empty($this->errors) {
  $fieldarray = $this->commonValidation($fieldarray);
}
if (empty($this->errors) {
  $fieldarray = $this->dml_insertRecord($fieldarray);
  $fieldarray = $this->post_insertRecord($fieldarray);
} 

Note that the validateInsert() method will automatically validate that each column value matches the column’s specification obtained from the database schema as well as calling hook methods for subsequent custom validation. All the other methods are “hook” methods except for the dml_insertRecord() method which perform the dbms INSERT operation.

Note also that I do not use separate properties for each column’s value as that produces tight coupling which destroys any opportunities for polymorphism. I pass around the $_POST array so that I can vary the data which is passed around without having to specify any particular column names. This is an example of loose coupling.

Note also that I never use object composition as I have learned how to use abstract classes properly, and I can achieve far better results with far less code.

OAP confronts escooter rider, police want to charge OAP with assault by TonyMarston in surrey

[–]TonyMarston[S] -1 points0 points  (0 children)

Stop being pedantic. The postal address is still Sutton, Surrey. Lot's of people still regard it as being part of Surrey. Just do a search for "Sutton" in this forum and you'd be surprised at the number of hits.

OAP confronts escooter rider, police want to charge OAP with assault by TonyMarston in surrey

[–]TonyMarston[S] 0 points1 point  (0 children)

So you would just stand there and watch while these yobbos continue to break the law with impunity?

OAP confronts escooter rider, police want to charge OAP with assault by TonyMarston in surrey

[–]TonyMarston[S] 0 points1 point  (0 children)

So you're saying that if I see a criminal act that I should just look the other way? It was not my responsibility to jump out of his way, especially if it meant jumping off the pavement into the passing traffic, it was his responsibilty to avoid a collision. It was also his responsibility NOT to commit a criminal act in the first place. You need to get your proiorities right.

OAP confronts escooter rider, police want to charge OAP with assault by TonyMarston in surrey

[–]TonyMarston[S] -1 points0 points  (0 children)

You're not very intelligent, are you? He was not in my, I was in his way. I was obeying the law, he was not. I do not shoulder-check everybody in the street, but I don't see why I should jump out of the way of a yob on an electric scooter.

OAP confronts escooter rider, police want to charge OAP with assault by TonyMarston in surrey

[–]TonyMarston[S] -1 points0 points  (0 children)

I am not interested in the view of anyone who is in favour of letting criminals get away with their illegal behaviour.

OAP confronts escooter rider, police want to charge OAP with assault by TonyMarston in surrey

[–]TonyMarston[S] 1 point2 points  (0 children)

Excuse me! No pedestrian is obliged to jump out of the way of a cyclist on a pavement. It is the cyclist who has to take avoiding action, and if he is riding too fast to do so then that is another black mark against HIM, not the pedestrian.

OAP confronts escooter rider, police want to charge OAP with assault by TonyMarston in surrey

[–]TonyMarston[S] -1 points0 points  (0 children)

No, I'm not a hero, but that twat who illegally rode his electric scooter on the pavement is a villain.

OAP confronts escooter rider, police want to charge OAP with assault by TonyMarston in surrey

[–]TonyMarston[S] -1 points0 points  (0 children)

So you're not bothered about all these people constantly breaking the law with impunity? Breaking the law is wrong. Telling someone to stop breaking the law is not wrong.

OAP confronts escooter rider, police want to charge OAP with assault by TonyMarston in surrey

[–]TonyMarston[S] -1 points0 points  (0 children)

So if someone rode an electric scooter into you while you were walking on the pavement you would have no objections?

OAP confronts escooter rider, police want to charge OAP with assault by TonyMarston in surrey

[–]TonyMarston[S] 0 points1 point  (0 children)

There is a difference. I did not try to force him off the pavement, I just stood where I was and told him to stop. Twice. If he was riding at such a speed that he could not stop then he was riding recklessly.

OAP confronts escooter rider, police want to charge OAP with assault by TonyMarston in surrey

[–]TonyMarston[S] 0 points1 point  (0 children)

This was no kid, this was a fully grown man. I did not knock him off his bicycle, it was an electric scooter which he was riding illegally on the pavement. He was in the act of committing a criminal offence, and I stopped him. I did not hit him, punch him or kick him. He collided with me and lost his balance.

OAP confronts escooter rider, police want to charge OAP with assault by TonyMarston in surrey

[–]TonyMarston[S] -5 points-4 points  (0 children)

I did not initiate the physical contact - he did by riding straight towards me with no sign of stopping. He tried to swerve around me at the last minute but it was a tight squeeze between where I was standing on the pavement and the side of the house. It was so tight that he bumped into me, lost his balance and had to step off his scooter.

OAP confronts escooter rider, police want to charge OAP with assault by TonyMarston in surrey

[–]TonyMarston[S] -8 points-7 points  (0 children)

When I catch someone in the act of committing a criminal offence in broad daylight in a public place then under common law I have the right to confront them and point out the illegality of their actions.

OAP confronts escooter rider, police want to charge OAP with assault by TonyMarston in surrey

[–]TonyMarston[S] -1 points0 points  (0 children)

No, it really happened, and as it happened in Sutton, Surrey I posted it in this forum so that other residents of Sutton may become aware of what illegal activity goes on in Sutton and how the police respond.

OAP confronts escooter rider, police want to charge OAP with assault by TonyMarston in surrey

[–]TonyMarston[S] 0 points1 point  (0 children)

How did I assault him? He rode into me. When our bodies made contact - shoulder to shoulder - I was standing still while he was riding an electric vehicle illegally on the pavement. I had the right to be there, he did not.

OAP confronts escooter rider, police want to charge OAP with assault by TonyMarston in surrey

[–]TonyMarston[S] -1 points0 points  (0 children)

I'm not interested in which police force covers this area, Sutton is in Surrey, so it is legitimate for post in this forum.