php_lang_ref:Language Reference >> References Explained >> Unsetting References

本文通过案例演示了在PHP中如何使用引用,并解释了当使用unset函数解除引用时的具体行为。即使原始变量名被unset,指向同一内存地址的其他变量仍然有效。
<?php
// +----------------------------------------------------------------------
// | Created by im-server.
// +----------------------------------------------------------------------
// | Language Reference >> References Explained >> Unsetting References
// +----------------------------------------------------------------------
// | Author: alexander <gt199899@gmail.com>
// +----------------------------------------------------------------------
// | Datetime: 2017-07-16 18:42
// +----------------------------------------------------------------------
// | Perfect Is Shit
// +----------------------------------------------------------------------

/**
 * 当 unset 一个引用,只是断开了变量名和变量内容之间的绑定。这并不意味着变量内容被销毁了。
 * case1
 */

namespace case1;
$a = 1;
$b =& $a;
unset($a);
var_dump($b);
/**
 * 输出:
 * int(1)
 */
Table users { id int [pk, increment] username varchar [not null, unique] password varchar [not null] email varchar phone varchar address text create_time timestamp [default: `CURRENT_TIMESTAMP`] status int [default: 1, comment: '0:禁用 1:正常'] role varchar [default: 'USER', comment: 'USER:普通用户 ADMIN:管理员'] points int [default: 0] total_spent decimal [default: 0.00] } Table categories { id int [pk, increment] name varchar [not null] description text create_time timestamp [default: `CURRENT_TIMESTAMP`] status int [default: 1] } Table products { id int [pk, increment] name varchar [not null] description text price decimal [not null] stock int [default: 0] image varchar category_id int create_time timestamp [default: `CURRENT_TIMESTAMP`] status int [default: 1, comment: '0:下架 1:上架'] sales_count int [default: 0, comment: '销量'] rating decimal [default: 0.00, comment: '平均评分'] update_time timestamp Ref: categories.id > products.category_id } Table cart_items { id int [pk, increment] user_id int [not null] product_id int [not null] quantity int [default: 1] create_time timestamp [default: `CURRENT_TIMESTAMP`] update_time timestamp [default: `CURRENT_TIMESTAMP`, on_update: `CURRENT_TIMESTAMP`] Ref: users.id > cart_items.user_id Ref: products.id > cart_items.product_id Unique: (user_id, product_id) } Table orders { id int [pk, increment] user_id int [not null] order_no varchar [not null, unique] total_amount decimal [not null] status int [default: 0, comment: '0:待付款 1:已付款 2:已发货 3:已完成 4:已取消'] address text phone varchar receiver_name varchar create_time timestamp [default: `CURRENT_TIMESTAMP`] pay_time timestamp ship_time timestamp complete_time timestamp payment_method varchar [comment: '支付方式:ALIPAY/WEIXIN/BANK'] payment_status int [default: 0, comment: '0:未支付 1:已支付 2:支付失败'] Ref: users.id > orders.user_id } Table order_items { id int [pk, increment] order_id int [not null] product_id int [not null] product_name varchar [not null] price decimal [not null] quantity int [not null] subtotal decimal [not null] Ref: orders.id > order_items.order_id Ref: products.id > order_items.product_id } Table product_reviews { id int [pk, increment] user_id int [not null] product_id int [not null] order_id int [not null] rating int [not null, check: `rating >= 1 AND rating <= 5`] content text images text [comment: '评价图片,多个图片用逗号分隔'] create_time timestamp [default: `CURRENT_TIMESTAMP`] status int [default: 1, comment: '0:隐藏 1:显示'] Ref: users.id > product_reviews.user_id Ref: products.id > product_reviews.product_id Ref: orders.id > product_reviews.order_id } Table payment_records { id int [pk, increment] order_id int [not null] payment_no varchar [not null, unique] amount decimal [not null] payment_method varchar [not null] status int [default: 0, comment: '0:待支付 1:支付成功 2:支付失败 3:已退款'] create_time timestamp [default: `CURRENT_TIMESTAMP`] pay_time timestamp transaction_id varchar [comment: '第三方支付交易号'] Ref: orders.id > payment_records.order_id } Table user_permissions { id int [pk, increment] user_id int [not null] permission varchar [not null, comment: '权限名称'] create_time timestamp [default: `CURRENT_TIMESTAMP`] Ref: users.id > user_permissions.user_id Unique: (user_id, permission) } 帮我修改
最新发布
07-08
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值