PHP Classes

PHP Class Constructor with Parameters: How to access all the class constructor parameters

Recommend this page to a friend!
     
  Info   Example   View files Files   Install with Composer Install with Composer   Download Download   Reputation   Support forum   Blog    
Ratings Unique User Downloads Download Rankings
Not yet rated by the usersTotal: 85 All time: 10,034 This week: 206Up
Version License PHP version Categories
speciala-rguments 1.0The PHP License5PHP 5, Language
Description 

Author

This class can show how to access all the class constructor parameters.

It is an example class with a constructor function that takes all its parameter values and store them in an array class variable.

Another class function can return the array with all the parameter values that were previously passed to the class constructor function.

Innovation Award
PHP Programming Innovation award nominee
December 2020
Number 3
PHP classes can have constructor functions that are called once a class object is created.

Like other types of functions, constructor functions can have a variable number of parameters.

This class demonstrates how to handle class constructor function calls by storing all the parameters in a way that they can be accessed later, regardless of the number of the parameters that were passed.

Manuel Lemos
Picture of adam berger
  Performance   Level  
Name: adam berger <contact>
Classes: 23 packages by
Country: Poland Poland
Age: ???
All time rank: 74521 in Poland Poland
Week rank: 197 Up2 in Poland Poland Up
Innovation award
Innovation award
Nominee: 8x

Winner: 2x

Example

<?php

          $adam
= "1 person";
         
$ginter = "2 person";
             
$bodzio = "3 person";
             
$endriu = "4 person";
             
$bandzo = "5 person";
             
             
         
           
$test = new special_arguments($adam, $ginter, $bodzio, $endriu, $bandzo);
      
$a = $test->car();
      
      
      
        foreach(
$a[0] as $person){
           echo
$person."<br>";
          }


Details

speciala-rguments

     Je?eli nie wiemy ile parametrów b?dziemy przekazywa? do konstruktora
     mo?emy zrobi? to w ten sposób.
     Nie musimy ingerowa? w sam? klas? za ka?dym razem kiedy dopisujemy
     kolejny parametr.
     Za?ó?my ?e mamy samochód w którym nie wiemy ile osób b?dzie podró?owa?,
     a chcemy przekaza? do konstruktora, za ka?dym razem inn? ilo?? osób.
     Czy mo?emy o zawartych w klasie regu?ach powiedzie?, ?e jest nowym wzorcem
     projektowym Special Arguments.
     Prze?lijcie wasze opinie na email <ber34@o2.pl>

     If you do not know how many parameters we pass to the constructor, 
     we can do it this way.
We do not need to interfere in the same class each time when 
we add another parameter.
Suppose that we have a car that does not know how many people will travel
and we want to pass to the constructor, each time a different number of people.
Are we about contained in the class rules say that it is a new design
pattern Special Arguments.
Please send your feedback by email  <ber34@o2.pl>

  Files folder image Files (4)  
File Role Description
Plain text file class_special_arguments.php Class Class source
Accessible without login Plain text file index.php Example Example script
Accessible without login Plain text file LICENSE Lic. License text
Accessible without login Plain text file README.md Doc. Documentation

The PHP Classes site has supported package installation using the Composer tool since 2013, as you may verify by reading this instructions page.
Install with Composer Install with Composer
 Version Control Unique User Downloads Download Rankings  
 100%
Total:85
This week:0
All time:10,034
This week:206Up