这个php构造是什么意思:$ html-> redirect("URL")? [英] What does this php construct mean: $html->redirect("URL")?

查看:88
本文介绍了这个php构造是什么意思:$ html-> redirect("URL")?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经在php的其他地方看到过这个->".我曾经学习过PHP的其中一本书中有此内容,但从未解释过.它是做什么的,它是如何工作的!

I've seen this "-> " elsewhere used in php. One of the books I used to learn PHP has this in it, but it is never explained. What does it do, how does it work!

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

The redirect bit I know, but what is happening with the $html variable and the redirect function?

提前谢谢!

推荐答案

注意:如果您不知道什么是对象",则下一段可能没有意义.我在最后添加了链接,以了解有关对象"及其含义的更多信息

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

This will access the method inside the class that has been assigned to HTML.

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

创建类并将其分配给变量时,可以使用'->'运算符来访问该类的方法.方法只是类内部的函数.

When you create a class and assign it to a variable, you use the '->' operator to access methods of that class. Methods are simply functions inside of a class.

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

Basically, 'html' is a type of object. You can create new objects in any variable, and then later use that variable to access things inside the object. Every time you assign the HTML class to a varaible like this:

$html = new html;

您可以像这样访问其中的任何功能

You can access any function inside of it like this

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

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

To learn more you are going to want to find articles about Object Oriented Programming in PHP

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

First try the PHP Manual:
http://us2.php.net/manual/en/language.oop.php
http://us2.php.net/oop

更多StackOverflow知识:
PHP类:何时使用:: vs.-> ;?
https://stackoverflow.com/questions/tagged/oop
https://stackoverflow.com/questions/249835/book-recommendation-for- learning-good-php-oop
为什么在基本功能上以及何时使用PHP OOP?
有什么好处OO编程?会帮助我编写更好的代码吗?

More StackOverflow Knowledge:
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构造是什么意思:$ html-> redirect("URL")?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆