你可以扩展别名吗 - 如果是的话 - 如何?

时间:2018-05-20 11:29:34

标签: php namespaces

我对命名空间没有多少经验,我唯一的例子是使用Laravel。

import random
import time
import json
import threading
import requests
from selenium import webdriver
from selenium.webdriver.support.ui import Select
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
from colorama import init
from colorama import Fore, Back, Style
from datetime import datetime

init(autoreset=True)

config = json.load(open("config.json"))
times = int(config['amount'])
delay = int(config['verifier_delay'])
username = config['username']
password = config['password']
read_file = open("accounts.txt", "r")
account = read_file.readlines()
acc_len = len(account)
acc_no=0

def verify(acc_no):
    if acc_no >= acc_len:
         print('Account number does not exist in file. ', acc_no)
         return
    real_account = account[acc_no]
    username = real_account[0:real_account.find(":")]
    password = real_account[real_account.find(":")+1:]
    print(username + password)
    print(acc_no)

for i in range(times):
    verify(i)

time.sleep(5)

假设有一个包含多个有用类的包。我如何将它们堆叠在一个别名下?你可以像在类定义中那样扩展别名吗?

<?php use use My\Full\Classname as Another; // <-- Alias // Want to add in import here to extend Faker alias to include more methods

class Foo extends Bar {}

我希望能够扩展另一个,所以我可以做另一个 - &gt; foo();是否可以使用别名?

1 个答案:

答案 0 :(得分:0)

这可以通过创建一个新类

来完成
class ExtendedAnother extends Another {
    function foo() {
        $this->bar();
        // Do foo here
    }
}

现在您只能执行以下操作

use ExtendedAnother as Another; // Has foo() method
Another->foo();

别名或命名空间不适用于类扩展,因此不能以您请求的方式使用。

相关问题