Click here to Skip to main content
16,016,229 members
Home / Discussions / Web Development
   

Web Development

 
QuestionIntegrate 3rd party Authenticator app Pin
Super Lloyd10-May-21 13:47
Super Lloyd10-May-21 13:47 
AnswerRe: Integrate 3rd party Authenticator app Pin
Richard Deeming18-May-21 4:06
mveRichard Deeming18-May-21 4:06 
GeneralRe: Integrate 3rd party Authenticator app Pin
Super Lloyd18-May-21 16:48
Super Lloyd18-May-21 16:48 
QuestionCSS not showing on my website! HELP! Pin
Gee_Suss 9-May-21 11:27
Gee_Suss 9-May-21 11:27 
AnswerRe: CSS not showing on my website! HELP! Pin
SeanChupas11-May-21 3:04
SeanChupas11-May-21 3:04 
QuestionFiltering an array of objects based on (another object/array of objects) Pin
Pavithran R8-May-21 9:07
Pavithran R8-May-21 9:07 
AnswerRe: Filtering an array of objects based on (another object/array of objects) Pin
jsc429-May-21 22:33
professionaljsc429-May-21 22:33 
QuestionPHP7, uasort method, return new instance Pin
jkirkerx23-Apr-21 8:12
professionaljkirkerx23-Apr-21 8:12 
I wrote this PHP 7.14.4 class to represent an object of Keys and Values, made up of Key Value. It uses IteratorIterator, which I have found to contains about 15 useful methods to do things like count(), append(), move() and uasort(). I wrote this sort of piecing together some concepts, and thought it would be a nice method to have in my swiss army knife.

I get this error message, and I understand what it says, and I have 1/2 a clue on how to fix it, but I can't visualize how to return a new instance of KeyValue.

Fatal error: Uncaught TypeError: Return value of KeyValues::uaSort() must be an instance of KeyValues, none returned in C:\App\Dev\PCAD\models\keyValue.model.php:52 Stack trace: #0 C:\App\Dev\PCAD\api\prices\priceSetUpdate.api.php(61): KeyValues->uaSort() #1 {main} thrown in C:\App\Dev\PCAD\models\keyValue.model.php on line 52

I called the method like this below ....
I'm surprised PHP didn't complain about my merge method concept that I wrote. I included the extra code so you can get an idea of what I'm doing and how I use it.

// Get and Merge KeyValues
foreach ($partKeyValues as $partKeyValue) {

   $referenceId = $partKeyValue->getValue();
   $taskVersions = TaskVersionsRepository::getTaskVersionsByReferenceId($referenceId);
   $taskKeyValues->merge($taskVersions);

}
// Very radical concept in object oriented programming, may crash, yes it crashed.
$taskKeyValues->uaSort();
class KeyValues extends IteratorIterator {

    public function __construct(KeyValues ...$keyValues)
    {
        parent::__construct(new ArrayIterator($keyValues));
    }

    public function count() : int
    {
        return $this->getInnerIterator()->count();
    }

    public function merge(KeyValues $keyValues)
    {
        foreach ($keyValues as $keyValue) {
            $this->getInnerIterator()->append($keyValue);
        }
    }

    public function uaSort(): KeyValues {
        $this->getInnerIterator()->uasort(
            function(KeyValue $a, KeyValue $b) {
                return $a->getValue() <=> $b->getValue();
            }
        );
    }

class KeyValue {

    private $key;
    private $value;

    public function __construct()
    {

    }

    public function getKey() { return $this->key; }
    public function setKey($key) { $this->key = $key; }

    public function getValue() { return $this->value; }
    public function setValue($value) { $this->value = $value; }    

}

So your probably wondering what the story here is on me working with PHP 7.4. I decided to help this company that got burned on a PHP 4.7 project last worked on in 2011, in which the designers and coders lost control of proper programming practices, going completely crazy with PHP which is typical. They put the presentation HTML in classes, and business logic in the presentation layer. Then their IT guy thought he could be a programmer and started working on it making it worst, because he thought the existing code was proper programming practices.

Whats weird, is that the IT company hosting the App suggested to the customer that they should upgrade from PHP 4.73 to PHP 8 to plug the security holes, thinking that the upgrade was like upgrading to Windows 10. So I went along with it, and began to realize that upgrading to PHP 8 was more like a quest to stop writing bad procedural code and embrace the power of object orientated programming in PHP 8. My goal is to get this right, do a great job, and not shame myself with what I deliver.

I'm starting to like PHP, and see why so many organizations use it to this date. This really hasn't been a journey of learning how to code in PHP, but more like a proper lesson in how to implement proper design principles for me. Perhaps this finally elevates me to a higher level of thinking.
If it ain't broke don't fix it
Discover my world at jkirkerx.com

AnswerRe: PHP7, uasort method, return new instance [Maybe Solved] Pin
jkirkerx24-Apr-21 9:53
professionaljkirkerx24-Apr-21 9:53 
Questionsearch word in code phpstorm Pin
sookitak18-Apr-21 4:06
sookitak18-Apr-21 4:06 
AnswerRe: search word in code phpstorm Pin
SeanChupas23-Apr-21 9:16
SeanChupas23-Apr-21 9:16 
QuestionMaster Detail CRUD using blazor Pin
sanket16413-Apr-21 20:52
sanket16413-Apr-21 20:52 
SuggestionRe: Master Detail CRUD using blazor Pin
Shaun C Curtis14-Apr-21 6:37
mvaShaun C Curtis14-Apr-21 6:37 
GeneralRe: Master Detail CRUD using blazor Pin
sanket16414-Apr-21 8:40
sanket16414-Apr-21 8:40 
AnswerRe: Master Detail CRUD using blazor Pin
Mycroft Holmes14-Apr-21 13:28
professionalMycroft Holmes14-Apr-21 13:28 
GeneralRe: Master Detail CRUD using blazor Pin
sanket16415-Apr-21 8:09
sanket16415-Apr-21 8:09 
GeneralRe: Master Detail CRUD using blazor Pin
Mycroft Holmes15-Apr-21 13:52
professionalMycroft Holmes15-Apr-21 13:52 
QuestionDo events like slider and drag and drop need to be well known? Pin
Oyee 202129-Mar-21 19:31
Oyee 202129-Mar-21 19:31 
AnswerModeration Pin
Nelek29-Mar-21 19:32
protectorNelek29-Mar-21 19:32 
AnswerRe: Do events like slider and drag and drop need to be well known? Pin
Richard Deeming29-Mar-21 21:42
mveRichard Deeming29-Mar-21 21:42 
QuestionHTML Rotate results in messed up and unresponsive design. Pin
Resource Link26-Mar-21 7:19
Resource Link26-Mar-21 7:19 
QuestionRefresh token API development and documentation Pin
kyclk1125-Mar-21 19:15
kyclk1125-Mar-21 19:15 
QuestionPHP7, how to create a json array of keyvalues from an object Pin
jkirkerx25-Mar-21 10:57
professionaljkirkerx25-Mar-21 10:57 
AnswerRe: PHP7, how to create a json array of keyvalues from an object Pin
jkirkerx26-Mar-21 11:18
professionaljkirkerx26-Mar-21 11:18 
QuestionHi, can someone help me with file-upload feature for my Angular app? Pin
kyclk1117-Mar-21 3:41
kyclk1117-Mar-21 3:41 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.