”。我以前学习PHP的其中一本书里面有这个,但是从来没有解释过。它有什么作用,它是如何工作的! 重定向位我知道,但是 $html 变量和重定向函数发生了什么? -6ren">
gpt4 book ai didi

php - 这个 php 结构是什么意思 : $html->redirect ("URL")?

转载 作者:塔克拉玛干 更新时间:2023-11-03 05:51:43 27 4
gpt4 key购买 nike

我在 php 的其他地方看到过这个“->”。我以前学习PHP的其中一本书里面有这个,但是从来没有解释过。它有什么作用,它是如何工作的!

重定向位我知道,但是 $html 变量和重定向函数发生了什么?

提前致谢!

最佳答案

注意:如果您不知道“对象”是什么,那么下一段可能没有意义。我在末尾添加了链接以了解有关“对象”及其含义的更多信息

这将访问已分配给 HTML 的类中的方法。

class html
{
function redirect($url)
{
// Do stuff
}
function foo()
{
echo "bar";
}
}
$html = new html;
$html->redirect("URL");

当您创建一个类并将其分配给一个变量时,您可以使用“->”运算符来访问该类的方法。方法只是类内部的函数。

基本上,“html”是一种对象。您可以在任何变量中创建新对象,然后使用该变量访问对象内部的内容。每次将 HTML 类分配给这样的变量时:

$html = new html;

你可以像这样访问其中的任何函数

$html->redirect();
$html->foo(); // echos "bar"

要了解更多信息,您需要查找有关 PHP 中面向对象编程的文章

首先尝试 PHP 手册:
http://us2.php.net/manual/en/language.oop.php
http://us2.php.net/oop

更多 StackOverflow 知识:
PHP Classes: when to use :: vs. ->?
https://stackoverflow.com/questions/tagged/oop
https://stackoverflow.com/questions/249835/book-recommendation-for-learning-good-php-oop
Why use PHP OOP over basic functions and when?
What are the benefits of OO programming? Will it help me write better code?

关于php - 这个 php 结构是什么意思 : $html->redirect ("URL")?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1234196/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com