当前位置:网站首页>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 go
I 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边栏推荐
- SQL server queries the table structure of the specified table
- C language beginner level - pointer explanation - paoding jieniu chapter
- 二维数组中的元素求其存储地址
- From C to capable -- use the pointer as a function parameter to find out whether the string is a palindrome character
- Deep reinforcement learning for intelligent transportation systems: a survey paper reading notes
- Kubernetes cluster log and efk architecture log scheme
- 处理数据集,使用LabelEncoder将所有id转换为从0开始
- tensorflow转pytorch笔记;tf.gather_nd(x,y)转pytorch
- How do you adjust the scope of activerecord Association in rails 3- How do you scope ActiveRecord associations in Rails 3?
- 后管中编辑与预览获取表单的值写法
猜你喜欢
MySql實戰45講【SQL查詢和更新執行流程】
[flutter] example of asynchronous programming code between future and futurebuilder (futurebuilder constructor setting | handling flutter Chinese garbled | complete code example)
内存泄漏工具VLD安装及使用
I2C 子系统(三):I2C Driver
基于can总线的A2L文件解析(2)
MySql实战45讲【行锁】
Xiaodi notes
HW initial preparation
MySQL Real combat 45 [SQL query and Update Execution Process]
SqlServer行转列PIVOT
随机推荐
Pytest (6) -fixture (Firmware)
Can netstat still play like this?
用docker 连接mysql的过程
Cancer biopsy instruments and kits - market status and future development trends
vfork执行时出现Segmentation fault
I2C 子系统(二):I3C spec
Update and return document in mongodb - update and return document in mongodb
函数栈帧的创建与销毁
模糊查询时报错Parameter index out of range (1 > number of parameters, which is 0)
45 lectures on MySQL [index]
Wechat - developed by wechat official account Net core access
基于can总线的A2L文件解析(2)
Baidu map - surrounding search
Use of check boxes: select all, deselect all, and select some
sql server 查詢指定錶的錶結構
敏捷认证(Professional Scrum Master)模拟练习题
I2C subsystem (I): I2C spec
js根据树结构查找某个节点的下面的所有父节点或者子节点
The left value and the right finger explain better
一文带你了解 ZigBee