当前位置:网站首页>PHP constructor with parameters - PHP constructor with a parameter
PHP constructor with parameters - PHP constructor with a parameter
2022-07-03 03:02:00 【Rich in starch】
problem :
I need a function that will do something like this: I need a function to do this :
$arr = array(); // This is the array where I'm storing data$f = new MyRecord(); // I have __constructor in class Field() that sets some default values$f->{'fid'} = 1;$f->{'fvalue-string'} = $_POST['data'];$arr[] = $f;$f = new Field();$f->{'fid'} = 2;$f->{'fvalue-int'} = $_POST['data2'];$arr[] = $f;When I write something like this: When I write something like this :
$f = new Field(1, 'fvalue-string', $_POST['data-string'], $arr);$f = new Field(2, 'fvalue-int', $_POST['data-integer'], $arr);// Description of parameters that I want to use:// 1 - always integer, unique (fid property of MyRecord class)// 'fvalue-int' - name of field/property in MyRecord class where the next parameter will go// 3. Data for field specified in the previous parameter// 4. Array where the class should goI don't know how to make a parametrized constructor in PHP. I don't know how to PHP Create a parameterized constructor in .
Now I use a constructor like this: Now I use this constructor :
class MyRecord{ function __construct() { $default = new stdClass(); $default->{'fvalue-string'} = ''; $default->{'fvalue-int'} = 0; $default->{'fvalue-float'} = 0; $default->{'fvalue-image'} = ' '; $default->{'fvalue-datetime'} = 0; $default->{'fvalue-boolean'} = false; $this = $default; }}Solution :
Reference resources : https://stackoom.com/en/question/dDXk边栏推荐
- [principles of multithreading and high concurrency: 1_cpu multi-level cache model]
- Joking about Domain Driven Design (III) -- Dilemma
- How to use asp Net MVC identity 2 change password authentication- How To Change Password Validation in ASP. Net MVC Identity 2?
- C language beginner level - pointer explanation - paoding jieniu chapter
- I2C 子系统(三):I2C Driver
- Deep Reinforcement Learning for Intelligent Transportation Systems: A Survey 论文阅读笔记
- 二维数组中的元素求其存储地址
- Getting started | jetpack hilt dependency injection framework
- I2C subsystem (IV): I2C debug
- Sqlserver row to column pivot
猜你喜欢

用docker 连接mysql的过程

Le processus de connexion mysql avec docker

Kubernetes cluster log and efk architecture log scheme

docker安装mysql

敏捷认证(Professional Scrum Master)模拟练习题-2

C language beginner level - pointer explanation - paoding jieniu chapter

Deep reinforcement learning for intelligent transportation systems: a survey paper reading notes

I2C subsystem (IV): I2C debug

SQL statement
![[principles of multithreading and high concurrency: 1_cpu multi-level cache model]](/img/7e/ad9ea78868126b149bd9f15f587e6c.jpg)
[principles of multithreading and high concurrency: 1_cpu multi-level cache model]
随机推荐
How to return ordered keys after counter counts the quantity
MySql实战45讲【索引】
SQL Server Query spécifie la structure de la table
I2C 子系统(二):I3C spec
SQL server queries the table structure of the specified table
Strategy application of Dameng database
Docker install redis
Parameter index out of range (1 > number of parameters, which is 0)
ASP. Net core 6 framework unveiling example demonstration [02]: application development based on routing, MVC and grpc
【富瀚6630编码存录像,用rtsp服务器及时间戳同步实现vlc观看录像】
MySQL Real combat 45 [SQL query and Update Execution Process]
[C language] MD5 encryption for account password
Xiaodi notes
Use optimization | points that can be optimized in recyclerview
Change cell color in Excel using C - cell color changing in Excel using C
Add MDF database file to SQL Server database, and the error is reported
How to implement append in tensor
[fluent] futurebuilder asynchronous programming (futurebuilder construction method | asyncsnapshot asynchronous calculation)
Add some hard dishes to the interview: how to improve throughput and timeliness in delayed task scenarios!
处理数据集,使用LabelEncoder将所有id转换为从0开始